views:

430

answers:

1
+1  Q: 

sem_init on OS X

I am working on some code which uses the pthread and semaphore libraries. The sem_init function works fine on my ubuntu machine, but on OS X the sem_init function has absolutely no effect. Is there something wrong with the library or is there a different way of doing it? This is the code I am using to test.

sem_t sem1;
sem_t sem2;
sem_t sem3;
sem_t sem4;
sem_t sem5;
sem_t sem6;

sem_init(&sem1, 1, 1);
sem_init(&sem2, 1, 2);
sem_init(&sem3, 1, 3);
sem_init(&sem4, 1, 4);
sem_init(&sem5, 1, 5);
sem_init(&sem6, 1, 6);

The values seem to random numbers, and they do not change after the sem_init call.

+2  A: 

Unnamed semaphores are not supported, you need to use named semaphores.

Nippysaurus