Waiting for multiple C ++ events

Is there a recommended way to wait for multiple inputs. For example, I want my program to be able to receive data from three sources:

Listen to the condition of the thread, for example. pthread_cond_wait ()

Take data from standard input, for example. GetLine ()

Listen to the socket, for example. accept ()

What is the best way to do this? Is a stream needed for each input source? Thanks

+5
source share
4 answers

, select(2). pthread_cond_timedwait -, .

, , - - , , , , , pthread_cond_wait/pthread_cond_timedwait, , select -.

+4

, accept(2) stdin - poll/select . ( , CV), poll , .

+7

Linux - pthread_cond_wait . eventfd, select/poll/epoll.

+3

, ; stdin, ?

If you really do not want to create three streams, the only option I can understand is to somehow modify or parameterize the libraries of streams, streams, and sockets to get a reference to the synchronization object.

0
source

All Articles