I have a multi-threaded system in which a main thread has to wait in blocking state for one of the following 4 events to happen:
- inter-process semaphore (sem_wait())
- pthread condition (pthread_cond_wait())
- recv() from socket
- timeout expiring
Ideally I'd like a mechanism to unblock the main thread when any of the above occurs, something like a ppoll() with suitable timeout parameter. Non-blocking and polling is out of the picture due to the impact on the CPU usage, while having separate threads blocking on different events is not ideal due to the increased latency (one thread unblocking from one of the events should eventually wake up the main one).
The code will be almost exclusively compiled under Linux with gcc toolchain, if that helps, but some portability would be good, if at all possible.
Thanks in advance for any suggestion