We have developed an app using wxWidgets. We are now incorporating graphics using Vulkan.
When using threads it is sometimes necessary to "Sleep" the main thread to wait for worker threads to stop. This method works when wxWidgets is not used. However when wxWidgets is used, any sleep function call causes all the threads to sleep.
We can solve this by appropriately calling the wx function "Yield" but this causes "shearing" in the Graphics for some reason.
Is there some other method we can use to cause the main thread to wait for worker threads to finish? This is all done in a highly speed critical process so would prefer an efficient solution which "decouples" wx from the threaded jobs.
Thanks a lot
Multithreading issues with wx application
- doublemax@work
- Super wx Problem Solver
- Posts: 474
- Joined: Wed Jul 29, 2020 6:06 pm
- Location: NRW, Germany
Re: Multithreading issues with wx application
That doesn't make any sense to me.However when wxWidgets is used, any sleep function call causes all the threads to sleep.
1) that shouldn't happen at all
2) it shouldn't be related to wxWidets
Maybe you're not describing it well.
Without knowing any details, i'd suggest to just create another thread that waits for the others to finish, and then send an event to the main thread (if needed).
Re: Multithreading issues with wx application
I'm not sure what your worker threads are doing, but the main (GUI) thread should never block. I would get a std::future from std::async, poll them in a single worker thread that then calls wxApp::CallAfter to send the result back to the main thread.
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: Multithreading issues with wx application
1. Don't put sleep in the main thread. It will block and freeze the UI
2. If your redrawing functions are in response to thread events then stop sending events fro threads
3. If there are things that need to be disabled, then when you are ready, just disable the parent like panel so that app stops interacting with the user
By any means avoid freezing main thread and sleep is a sure way to do just that!
2. If your redrawing functions are in response to thread events then stop sending events fro threads
3. If there are things that need to be disabled, then when you are ready, just disable the parent like panel so that app stops interacting with the user
By any means avoid freezing main thread and sleep is a sure way to do just that!
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?