Reputation: 2120
As the title says, can I do this with a POSIX file descriptor? In my case, it's a serial device where I have one thread reading and another one writing.
Upvotes: 1
Views: 423
Reputation: 22261
Yes, you can do that with a serial port, no problem.
You could do it with a regular file too, though it would probably be confusing since you'd have to carefully manage the contents of the file so that the reader and writer aren't stepping on each other and especially carefully manage the seek pointer (use pread()
and pwrite()
which don't depend on the seek pointer). Obviously, with a serial port which has separate in & out directions and no concept of a seek pointer, it's more straightforward.
Upvotes: 4