26 a thread unsafe function that returns a pointer to

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: .3 Protecting Shared Variables with Semaphores A semaphore, ×, is a global variable with a nonnegative integer value that can only be manipulated by two special operations, called È and Î : ¯ È × : while ¯ Î × : s++; ´µ ´µ (s <= 0); s--; The names È and Î come from the Dutch Proberen (to test) and Verhogen (to increment). The È operation waits for the semaphore × to become nonzero, and then decrements it. The Î operation increments ×. The test and decrement operations in È occur indivisibly, in the sense that once the predicate × ¼ becomes false, the decrement occurs without interruption. The increment operation in Î also occurs indivisibly, in that it loads, increments, and stores the semaphore without interruption. 580 CHAPTER 11. CONCURRENT PROGRAMMING WITH THREADS The definitions of È and Î ensure that a running program can never enter a state where a properly initialized semaphore has a negative value. This property, known as the semaphore invariant, provides a powerful tool for co...
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