phdeniel/nfs-ganesha — Issue #65: SemN does not work is "N =1"
Author: phdeniel
Created: 2012-03-08 10:23:16+00:00
State: open

Initializing a "semaphore_t" ( with semaphore_init(&x, 1) ), leads to a deadlock.

Here is the test case by Mx about this:

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include
#include
#include
#include
#include
#include "SemN.h"
#include "log_macros.h"

semaphore_t x;

void *sem_me(void *arg)
{
int me = (int)arg;
semaphore_P(&x);
printf("%d: Got it, count is %d\n", me, x.count);
sleep(3);
semaphore_V(&x);
printf("%d: dropped it, count is %d\n", me, x.count);
}

int main()
{
int i;
pthread_t t[3];

semaphore_init(&x, 1);

for (i=0; i < 3; i++) {
pthread_create(t+i, NULL, sem_me, (void *)i);
}

for (i=0; i < 3; i++) {
pthread_join(t[i], NULL);
}

return 0;
}