Opening a semaphore with sem_open
will also initialize it to any given value, is there any way to open a semaphore that is used by another thread without changing its value?
CodePudding user response:
What you say isn't true. Using sem_open
to open an existing semaphore doesn't change its value.
So, to answer you question,
sem_t *sem = sem_open( name, O_RDWR );
if ( sem == SEM_FAILED ) {
perror( NULL );
exit( EXIT_FAILURE );
}