Single semare critical region problem???

view full story

http://www.unix.com – Hi guys, I hope everybody is doing fine. I have written this small program which solves the critical region problem. Only on of the two threads can make changes to a common variable called counter. I am using two semaphores, is it possible to write the same program using only one semaphore? Here have a look at my code Code: $ cat practise.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <pthread.h> #include <semaphore.h> #include <sys/sem.h> int count = 0; int pargc; char **pargv; sem_t sem1; sem_t (HowTos)