简体   繁体   English

wxWidgets 应用程序的多线程问题

[英]Multithreading issues with wxWidgets application

We have developed an app using wxWidgets.我们使用 wxWidgets 开发了一个应用程序。 We are now incorporating graphics using Vulkan.我们现在正在使用 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.此方法在不使用 wxWidgets 时有效。 However when wxWidgets is used, any sleep function call causes all the threads to sleep.但是,当使用 wxWidgets 时,任何 sleep function 调用都会导致所有线程休眠。

We can solve this by appropriately calling the wx function "Yield" but this causes "shearing" in the Graphics for some reason.我们可以通过适当地调用 wx function “Yield”来解决这个问题,但这会由于某种原因导致图形中的“剪切”。

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.这一切都是在一个高速关键过程中完成的,因此更喜欢一个有效的解决方案,将 wx 从线程作业中“解耦”。

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).如果您使用std::thread (或使用wxThread::Wait() ,通常的解决方案是仅join()它们,但现在您应该在代码中使用标准 class )。 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.如果这是一个问题——即你不只在应用程序关闭时这样做,当没有更多 windows 时,主线程不再分派消息不是问题——一个简单的解决方案是只是继续检查线程是否已经/已经定期完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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