Serial I/O in two different threads

I need to read from my rs-232 port in one thread and write in my other thread. I am using fopen, fgetc, and fputc. I plan to get the file descriptor number and opening the file in the second thread using fdopen.

One thread only reads and one thread only writes. Does anyone know if this will work? I can use mutex locks if necessary.

Thanks,
Robert
Here's a cool example of serial I/O using Boost Asio:
http://boost.2283326.n4.nabble.com/Simple-serial-port-demonstration-with-boost-asio-asynchronous-I-O-td2582657.html

All of the threading and asynchronous multiplexing is handled for you by the Asio library.

But I do recognize that you have not acknowledged my earlier suggestions to use Boost for this. To do this without Asio, you will need to use a mutex. You cannot safely read and write to a single file descriptor from separate threads. There are atomicity guarantees in some circumstances (pipes for example), but I do not think it applies to serial devices.
Topic archived. No new replies allowed.