) Do not operate the MFC control in the thread function. Do not call the updatedata function in the thread to update the user interface. Instead, try to send messages, operate controls in the message response function of the main thread;
2) It is not recommended to use sendmessage to send messages to the main thread, because it is synchronous and congested. You can use postmessage instead;
3) when the thread exits, try not to use the terminatethread function, and try to let the thread quit on its own;
4) When a thread exits, it must wait for the worker thread to exit before the main thread exits. However, do not use waitforsingleobject or waitformultiobjects in the main thread to wait for the thread to end because it may cause a deadlock, when the main thread uses these two functions, the main thread is suspended, especially in the (1) and (2) cases, the worker thread is still calling Resources in the main thread, this causes a deadlock;
5) To prevent deadlock, try to use the msgwaitformultipleobjects function, because the function can wait for the thread handle to have a signal while waiting, and wait for the message without causing a deadlock;
Original address: http://software.intel.com/zh-cn/blogs/2011/08/03/windows-2? Cid = Sw: prccsdn1945