How to use same handle in seperate thread
-
I have a serial port class which continously polls the serial port and writes to the serial port as needed. I have a seperate thread for reading from the serial port. My problem is that I created the handle for the serial port in the main thread to be used when writing to the serial port, but I need to use that same handle in the other thread so that I can read from the serial port. I passed the handle to the worker thread, but I can't use it because it's not part of the thread's handle map. How can I get a handle to the serial port in the worker thread? Mark Lenz
-
I have a serial port class which continously polls the serial port and writes to the serial port as needed. I have a seperate thread for reading from the serial port. My problem is that I created the handle for the serial port in the main thread to be used when writing to the serial port, but I need to use that same handle in the other thread so that I can read from the serial port. I passed the handle to the worker thread, but I can't use it because it's not part of the thread's handle map. How can I get a handle to the serial port in the worker thread? Mark Lenz
When I need to make that I use a global Variable with the handle that I need to use. For example If I have a conecction with a database, I don't use diferent conections for each handle, I put the connection pointer into a global variable, that is acceded for each handle, and this work, i don't Know if you will have any problem with this practice. I hope to help you... Carlos Antollini. :bob: Is today Friday? No Bob!!!
-
I have a serial port class which continously polls the serial port and writes to the serial port as needed. I have a seperate thread for reading from the serial port. My problem is that I created the handle for the serial port in the main thread to be used when writing to the serial port, but I need to use that same handle in the other thread so that I can read from the serial port. I passed the handle to the worker thread, but I can't use it because it's not part of the thread's handle map. How can I get a handle to the serial port in the worker thread? Mark Lenz
take a look at DuplicateHandle, and use 1 handle for writing and the other for reading.. hope this helped :) B.Bruggeman