c++ - Select() system call in threads? -


I am reading data from multiple serial ports. Currently, I set up a custom signal handler (by setting the handler on file descriptor information ) And using the thread to wade the thread. I was searching for a way to separate threads with unique signal handlers, in this regard I came to know that to use the system call.

Now I have the following questions:

  1. If I am using a thread (QT) then where should I place the selected system call to monitor the serial port?
  2. Is the selected system call thread safe?
  3. Is this CPU intensive because there are many things in my app with GUI updates?

Please mind, if you find these questions ridiculous, I have never used such a mechanism for serial communication.

select this definition definition I personally poll I recommend - it has a better interface and the system can handle the descriptor in any number instead of the defining range.

If I understand correctly, then based on the status of some of the distributors you have based threads. A better way would be to have your own statement of thread and choose the call yourself. You are viewing, the system does not modify the situation, and as long as you use the thread-local variable, it will be safe though, you definitely want to make sure that you do not close a statement From which a thread depends.

Leaving to use select / select with a timeout will "wait" to the kernel side, which means that the thread is usually Is placed on gold. While the thread is sleeping it is not using any CPU time on the other side without a timeout, for a loop on a selection call a little longer / will give you a higher CPU usage, because you constantly Spinning in the loop.

Hope this will help.

EDIT: Select / poll can have unexpected results while working with same descriptor in multiple threads The simple reason for this is that the first thread can be awakened because the descriptor is ready to read, but the second thread has to wait " next " available for reading ".

Until you write select on multiple authors on the same descriptor, you should not have problems.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -