Hello,
I have a program where the serial port is opened and closed in the main thread. All outgoing communication is handled in the main thread, while another thread is responsible for handling all incoming data. When the user wants to close the serial port, a variable is set. This is detected by the other thread and the thread function will end. In my main thread, I call the function CmtWaitForThreadPoolFunctionCompletion to wait for the second thread function to finish before actually closing the serial port.
Problem: sometimes the main thread hangs at the function CmtWaitForThreadPoolFunctionCompletion, while the thread function is already finished for a long time. I can only end my program the hard way (Ctrl-Alt-Delete, or break the execution when debugging). I really have no idea why the main thread does not continue. Is there anybody who knows why this happens. Note that I call the CmtWaitForThreadPoolFunctionCompletion with the OPT_TP_PROCESS_EVENTS_WHILE_WAITING attribute.