I am trying to create a lock using sem_wait()
and I have a printf
before and after the sem_wait
call. (I do not see this being printed: printf("after sem wait ");
) The sem_wait
call never returns.
sem_t* sem;
Thank you
int 32_t retVal = -1;
printf("before sem wait ");
retVal = sem_wait(sem);
printf("after sem wait ");
How do I debug this issue?
The argument to
sem_wait
must to point to an actualsem_t
object which you've initialized usingsem_init
. For example:Of course if you're using this object for actual signalling, you'll also need to arrange to call
sem_post()
elsewhere to increment the semaphore.