简体   繁体   中英

Multithreading issues with wxWidgets application

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

You should never use "Sleep" to wait for the threads to finish. The usual solution is to just join() them if you use std::thread (or use wxThread::Wait() , but by now you should be using the standard class in your code instead). The trouble with doing this is that this would block the main thread, making your application appear hung. If this is a problem -- ie you don't do it only on application shutdown, when there are no more windows, and so it's not a problem that the main thread doesn't dispatch the messages any more -- one simple solution is to just keep checking if the thread(s) has/have finished periodically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM