federicoporritos84
federicoporritos84

Reputation: 11

Open semaphore without changing its value

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?

Upvotes: 0

Views: 174

Answers (1)

ikegami
ikegami

Reputation: 385556

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 );
}

Upvotes: 1

Related Questions