Figure 1129 lists the common exceptions see 77 for a

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: L2 0 0 -1 -1 Unsafe region -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 P(s) Initially s=1 H2 1 1 0 0 0 0 1 1 1 1 1 1 1 1 1 1 H1 P(s) L1 U1 S1 V(s) T1 Thread 1 Figure 11.16: Safe sharing with semaphores. The states where surrounds the unsafe region. × ¼ define a forbidden region that 11.4.4 Posix Semaphores The Posix standard defines a number of functions for manipulating semaphores. This section describes the three basic functions, sem init, sem wait (È ), and sem post (Î ). A program initializes a semaphore by calling the sem init function. 2 ½. A semaphore that is used in this way to protect shared variables is called a binary semaphore because its value is always ¼ or 11.4. SYNCHRONIZING THREADS WITH SEMAPHORES #include <semaphore.h> int sem init(sem t *sem, int pshared, unsigned int value); 581 returns: 0 if OK, -1 on error The sem init function initializes semaphore sem to value. Each semaphore must be initialized before it can be used. If sem is being used to synchronize concurrent threads associated with the same process, then pshared is zero. If sem is being used to synchronize concurrent processe...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online