Here the blocking function stands for any functions that cause the current thread enter the wait state, such as Sleep(),WaitForMultipleObject() and so on.
The reason to avoid using blocking function in main thread is that if the main thread is blocked and the thread creates any windows, it can’t process any message in its message queue. Other thread in the process may become deadlocked.
In fact, it would be much better to set a timer in another working thread, so that the main thread still works.
本文探讨了在软件开发过程中避免使用可能导致主线程进入等待状态的阻塞函数的原因。如果主线程被阻塞且创建了窗口,则无法处理消息队列中的任何消息,这可能会导致进程中的其他线程出现死锁。建议在工作线程中设置定时器,以确保主线程的正常运行。
480

被折叠的 条评论
为什么被折叠?



