Windows API / C / C ++
Windows API/C/C++
1. .... 2. .... 3. .... 4. while (flag1 != flag2) 5. { 6. SleepEx(100,FALSE); //waiting for flags to be equal (flags are set from another thread). 7. } 8. ..... 9. .....如果这些标志在7秒后彼此不相等,我想继续第8行。
If the flags don't equal each other after 7 seconds, I would like to continue to line 8.
我们将不胜感激。谢谢。
Any help is appreciated. Thanks.
推荐答案如果您正在等待设置特定标志或等待某个时间,可能会采用一种更为简洁的解决方案使用自动/手动重置事件。这些是为在线程之间发出信号而设计的,并在它们之上设计了非常丰富的API。例如,您可以使用WaitForMultipleObjects API,该API需要一个明确的超时值。
If you are waiting for a particular flag to be set or a time to be reached, a much cleaner solution may be to use an auto / manual reset event. These are designed for signalling conditions between threads and have very rich APIs designed on top of them. For instance you could use the WaitForMultipleObjects API which takes an explicit timeout value.
更多推荐
为while循环创建超时的最干净方法是什么?
发布评论