Home » Community » Newbie corner » WhenAction() -> ProcessEvents() -> WhenAction() -> hang, crash :-) (I'm probably stretching reentrancy of the GUI callbacks too far)
Re: WhenAction() -> ProcessEvents() -> WhenAction() -> hang, crash :-) [message #52840 is a reply to message #52838] |
Mon, 09 December 2019 12:00 |
Oblivion
Messages: 1092 Registered: August 2007
|
Senior Contributor |
|
|
Hello Frank,
Adding to what Koldo and Mirek said,
Quote:
What is the most appropriate container in U++ to implement a FIFO queue? T
IME, BiVector for FIFO/LIFO queue of moveable types, and BiArray for FIFO/LIFO queue of non-moveable/quirky types.
BiVector and BiArray are bi-directional random access containers, allowing adding or removing elements from both ends in a constant amortized time.
Quote:
Hmm... I can see that U++ has its own class Mutex and ConditionVariable. And they appear to be less convoluted (objectified) than the C++11 std::mutex and std::condition_variable (geez... if I didn't know the bare C libpthread version, I would probably just shake my head in disbelief).
IMHO, as I said elsewhere, you should really look into Upp::AsyncWork or Job. I'd suggest using Job here, not because I am the author of it , but from what you describe, it seems that it suits your needs better:
- Unlike Upp::AsyncWork, it does not require a pre-allocated thread-pool. It is a single, scope-bound worker thread that can be used as a dedicated thread.
- Unlike Upp::AsyncWork, it is guaranteed to run the desired function in another thread.
- Unlike Upp::Asyncwork, it has an internal latch: if a work is already in progress, then calls to Job::Do method will simply return false.
- Just like AsyncWork it has a result gathering, thread cancellation and exception propagation mechanisms.
I've attached the Job package and the multithreaded version of U++'s AnimatedHello example, running on Job. It demonstrates a one way of constantly updating the display from another thread, and handling gui locks/threads. Hope it helps.
(Note it can also be written almost identically using Upp::AsyncWork. But you'll have to provide a latch yourself, and also it will bring in the overhead of a pre-allocated thread pool)
Use CTRL + D to start animation, and CTRL + C to stop animation.
And let me know if you encounter any problem or have any questions.
Best regards,
Oblivion
-
Attachment: Example.zip
(Size: 8.97KB, Downloaded 199 times)
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Mon, 09 December 2019 12:05] Report message to a moderator
|
|
|
|
|
WhenAction() -> ProcessEvents() -> WhenAction() -> hang, crash :-)
By: xrysf03 on Sun, 08 December 2019 15:21
|
|
|
Re: WhenAction() -> ProcessEvents() -> WhenAction() -> hang, crash :-)
By: koldo on Sun, 08 December 2019 16:22
|
|
|
Re: WhenAction() -> ProcessEvents() -> WhenAction() -> hang, crash :-)
By: xrysf03 on Sun, 08 December 2019 20:57
|
|
|
Re: WhenAction() -> ProcessEvents() -> WhenAction() -> hang, crash :-)
By: mirek on Mon, 09 December 2019 08:55
|
|
|
Re: WhenAction() -> ProcessEvents() -> WhenAction() -> hang, crash :-)
By: Oblivion on Mon, 09 December 2019 12:00
|
Goto Forum:
Current Time: Wed Apr 24 06:16:59 CEST 2024
Total time taken to generate the page: 0.02297 seconds
|