I am unable to close a serial port handle that was successfully opened in blocking mode. The reason, I believe, is that a thread was blocked on a read and then terminated. Is there a way to free a blocked thread in software from a blocked serial port access so the thread can be properly terminated or to force the port to close?
Yes, I have tried those and others both before terminating the thread to see if it unblocks it and after to see if it will allow closure of the serial port; both had no effect. I would think that someone would have run in this problem already but perhaps they just band-aid the problem by putting the port in polling mode. Did anyone figure out how to use a serial port in blocking mode and still be able to close it from another controlling thread?
I am afraid that I used your “band-aid”. In my case I am doing a lot of ethernet I/O so it was easy to put it in the polling for that.
How are you terminating your threads? Externally? I would avoid that. Try using a mutex or semaphore to tell your thread to terminate itself. Then you can do cleanup.