Is there a way to do multiple increments / decrements on distinct semaphores in one (atomic) operation?
I saw that in SysV it is possible to do this and I was wondering if there was a way to do the same using POSIX API.
Here's what I would like to do (in SysV):
sem[0].sem_num = 0;
sem[0].sem_op = 1;
sem[0].sem_flg = 0;
sem[1].sem_num = 1;
sem[1].sem_op = -1;
sem[1].sem_flg = 0;
semop(semid, sem, 2)
Is there a way to do the same in POSIX?
Is there a way to do same using
semaphore.h
?
No, it is not possible.
Is there a way to do the same in POSIX?
The code you posted is using XSI extension to POSIX. Generally, even the standard states that if you are on POSIX compatible platform, you may use XSI extension with confidence that it will be available.