Perror Function
What does the second argument POSIX semaphore function sem_init() do?
res = sem_init(&produced, 0, 1);
if (res != 0) {
perror(“Semaphore creation failed”);
exit(EXIT_FAILURE);
}
res = sem_init(&consumed, 0, 0);
if (res != 0) {
perror(“Semaphore creation failed”);
exit(EXIT_FAILURE);
}
int sem_init(sem_t *sem, int pshared, unsigned int value);
sem_init initializes the semaphore object pointed to by sem. The count associated with the semaphore is set initially to value.
The pshared argument indicates whether the semaphore is local to the current process ( pshared is zero) or is to be shared between several processes (pshared is not zero).
Turkey Giveaway
