PaulDaviesC
PaulDaviesC

Reputation: 1261

Structure of sem_t and implementation of semaphores

In C programming language why do we need a special sem_t type for defining the semaphore? Couldn't that been an integer?How is sem_t defined? How is the functions sem_post and sem_wait implemented? EDIT:An example implementation like GNU C library will be great.

Upvotes: 3

Views: 11054

Answers (1)

Martin James
Martin James

Reputation: 24857

Semaphores are OS kernel managed objects, so sem_t will be OS-specific, as will be the signal/wait calls since they also necessarily call into the OS kernel.

Usually, the semaphores are implemented by a unit count and a queue for any waiting threads.

Upvotes: 5

Related Questions