[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Concurrent read / write of serial port

Posted on 2006-07-14
4
Medium Priority
?
586 Views
Last Modified: 2010-04-21
I have a serial port access class which wraps the termios API. This serial port in some situations is used in a multithreaded environment. In this case it will be shared by 2 threads but I can guarantee that 1 will perform output only, and the other will perform input only. Does this require a mutex to access the object?

I can't find any documentation on the thread-safety of read(2) and write(2), or termios(3). I guess it really depends on the implementation, but given that read, write and the termios API are POSIX-compliant, does anyone know if POSIX specifies the thread-safety of these functions?

--Rob
0
Comment
Question by:boycy
  • 2
  • 2
4 Comments
 
LVL 8

Expert Comment

by:manish_regmi
ID: 17106913
> does anyone know if POSIX specifies the thread-safety of these functions?

No the POSIX does not say anything about thread safety of those functions. This means that thread safety is not guranteed and one should assume that they are not thread safe.

> Does this require a mutex to access the object?
At the hardware level, Serial ports have seperate pins for data transmission and reception.
So, you may not need to protect read from writes.

regards
Manish Regmi
0
 
LVL 6

Author Comment

by:boycy
ID: 17106951
Granted the hardware level is fine for concurrent read/write - after all, it is full duplex. I would *assume* that providing an API which removes this full duplex ability would be a really silly idea; however assumptions are not good things. If there is any doubt at all as to whether these functions are thread-safe then I cannot use them. I'm having real trouble finding any information on this subject.
0
 
LVL 8

Accepted Solution

by:
manish_regmi earned 500 total points
ID: 17106982
A discussion on red hat forum also suggests it is safe.

http://sources.redhat.com/ml/ecos-discuss/2006-04/msg00219.html
So under Linux it may be safe but may not be for other OS.

Also since POSIX does not confirm thread safety. You can protect them with mutex for safety.

regards
Manish Regmi
0
 
LVL 6

Author Comment

by:boycy
ID: 17107000
Manish, thanks :)
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question