Skip to Main Content
Operating Systems: Concurrent and Distributed Software Design
book

Operating Systems: Concurrent and Distributed Software Design

by Jean Bacon, Tim Harris
March 2003
Intermediate to advanced content levelIntermediate to advanced
912 pages
27h 17m
English
Pearson Business
Content preview from Operating Systems: Concurrent and Distributed Software Design

10.5. Styles of use of semaphores

Semaphores can be used for a range of purposes. In the following sections we will see that they can be used to achieve (1) mutual exclusion; (2) synchronization of cooperating processes and; (3) management of multiple resource allocation. These different usages are achieved through varying the initial integer value of the semaphore as well as working with different orderings of the semWait () and semSignal () methods.

10.5.1. Mutual exclusion

A semaphore initialized to 1 may be used to provide exclusive access to a shared resource such as a data structure.

MyClass DataStructure // shared data structure 

Semaphore lock = new SemaphoreImplementation(1);

To use a semaphore:

 non-critical instructions lock.semWait(); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Principles of Concurrent and Distributed Programming, Second Edition

Principles of Concurrent and Distributed Programming, Second Edition

M. Ben-Ari
Operating Systems in Depth

Operating Systems in Depth

Thomas W. Doeppner

Publisher Resources

ISBN: 0321117891Purchase book