In a class, we’ve had to use semaphores to accomplish work with threads.
The prototype (and header file) of sem_init is the following:
int sem_init(sem_t *sem, int pshared, unsigned int value);
but I don’t understand what the value variable is used for. According to opengroup.org:
value is an initial value to set the semaphore to
“value is a value…” How does that help, what is it used for?
sem_init() initializes a pointed to semaphore (first parameter), with value (last parameter), and finally I believe this is actually what you were asking, int pshared you can think of like a flag. If pshared == 1 then semaphore can be forked.
EDIT: semaphore has int value because you would use a function such as sem_wait(sem_t* sem) to decrement pointed to semaphore. If it’s negative, then block.