Reputation: 2874
I am new with the concept of semaphore, I looked at some online examples and I understood that if we are using threads we can use predefined elements like
/* The mutex lock */
pthread_mutex_t mutex;
/* the semaphores */
sem_t full, empty;
and for using them we can again take advantage of predefined function like:
/* acquire the empty lock */
sem_wait(&empty);
/* acquire the mutex lock */
pthread_mutex_lock(&mutex);
But my question is that if I don't use threads and just want to use processes is there any predefined items like above or I should write semaphore and ... from scratch???
Upvotes: 1
Views: 144
Reputation: 711
There is a lot of cross process syncronization primitives including named semaphore. Usually cross process primitives use a name to determine unique instance. For example if you send a same name to:
sem_open(const char *name, int oflag)
It will create new or open existing (created from other process) semaphore. All you need is to make sure that name is unique in system and same for all of your processes.
Upvotes: 2