#include <semaphore.h>
sem_t* x;
int main ()
{
x = sem_open("x", O_CREAT, 0, 0);;
sem_wait(x); sem_wait(x); sem_wait(x);
std::cout << "\ndone\n";
}
This code shouldn’t even pass the first sem_wait() but on my system it reaches the end of main(). Everything I have read, such as here and here, say that, although Mac OS X does not support sem_init(), it does support sem_open(). However, using sem_open() as above hasn’t fixed the problem. I’m running OS X 10.5.7.
Try putting
sem_unlink("x");beforesem_open(), I’m sure it’s not your first attempt on it. And mode of 0 won’t let you do much with it, unless you remove it. Also, do check your calls for errors, it will if not resolve, but, at least, amend your questions.