0

i am in a very sticky situation as i am unable to figure out the problem with my producer-consumer problem using pthreads. the code compiles but when i run the code nothing happens and the expected output does not show. i believe there is a probelem in my producer and consumer threads with the if/else statement but i may be something else. the code is as shown below:

To compile it on command line:

gcc -pthread -lrt semaphore.c -o semaphore  

Once you run the program it dosent display the correct output

1 Answers1

1

You might want to consider some sample output to go with it; but I noticed that your producer and consumer threads start by:

int rNum = rand() / RAND_DIVISOR;
sleep(rNum);

Simply removing this from both threads made your program work. On my edition of linux, RAND_MAX is 2^31, so these could cause an up to 21 second sleep in each thread.

mevets
  • 10,070
  • 1
  • 21
  • 33