Good afternoon. I work with semaphores, for mysterious reasons for me, even if I immediately try to use it after initializing the semaphore, it fails, sem_trywait returns -1.
for(int i = 0; i< 5; i++) { sem_init(&utensils[i], 0, 1); sem_trywait(&utensils[i]); //returns -1 always! //create new thread processes for the philosophers pthread_create(&phs[i], NULL, philosopher, &num[i]); //check if the threads are created assert(!(phs[i] == 0)); }
(void*) &philosopher- continues to wander from option to option. - AnTerrnomeaningless without specifying a platform.78on many platforms isENOSYS, i.e. "function not implemented", i.e. semaphores in this implementation are simply not supported at all. Open<errno.h>and see what78on your platform. - AnTperrorafter initialization to print a meaningful error message. - AnT