If I have more than one semaphore, how can I create a process block until at least one of the semaphores is free? I know I can do this with a wait loop, for example:
int multiple_sem_wait(sem_t **sems, int num_sems) {
while (true) {
for (int i = 0; i < num_sems; ++i) {
if (sem_trywait(sems[i]) == 0) {
return i;
}
}
}
}
But is there a way to do this without employment? Perhaps there is some kind of IPC method other than semaphores that I should use?
thank
source
share