SlideServe
Menu
Préférences
© SlideServe · v2026

Understanding Semaphores and Their Role in Process Synchronization

bela avatar
17 diapositives · 334 Views · Aug 06, 2014

This text delves into semaphores, critical tools for managing access to shared resources in parallel processes. It discusses the mechanisms of semaphore statements, including request and release actions, to enforce mutual exclusion within critical sections. It highlights the importance of coordination statements that ensure exclusive execution and outlines the function of region statements as a structured approach to synchronization. Examples, such as the producer-consumer problem, illustrate the practical application of semaphores and region statements in achieving effective concurrency control in computing.

Understanding Semaphores and Their Role in Process Synchronization - slide 1
01 / 17Understanding Semaphores and Their Role in Process Synchronization
1 / 17

Télécharger la présentation

Understanding Semaphores and Their Role in Process Synchronization
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. 1.8 Semaphore Statement • One of the main problems in coordinating parallel processes is the management of access to shared resources. • Mechanisms • Grouped statements (1.7) • Semaphore statement (1.8) • Region statement (1.9)

  2. An example for a critical section, which shall be executed atomically: Fig. 1.8, P.57 (splitting one statement to two, to make it possible to be interleaved with others)

  3. To prevent unwanted interferences, we can use • grouped statements • It is a locking device. Disallows any action by a parallel process until the process executing the sequence completes. • We want as much parallel processing as possible. • General constructs that achieve locking and coordination between processes are referred to as synchronization constructs.

  4. Semaphore statements • request(r), release(r) • request(r): • <await r>0; r:=r-1> • release(r): • r:=r+1

  5. Use of semaphores for mutual exclusion • Mutual exclusion problem: devise a protocol, that contains critical, non-critical, and coordination statements; where coordination statements guarantee exclusive execution of the critical sections. • Example: Fig. 1.9, p. 60

  6. A location containing a request(r) statement: is a checkpoint, synchronizing the process with other processes containing request(r) and release(r) statements, on the same semaphore variable r. • An important assumption: variables used in the protocol for coordination between the processes (semaphore variables) are not modified in the critical sections. • Problem 1.4

  7. Mutual exclusion of multiple processes by semaphores. • Fig. 1.10, p. 62

  8. Other uses of Semaphores • To protect critical sections: request-release pairs appear within the same process. • Semaphores can be used in other signaling and synchronizations. • Fig. 1.12, p. 64

  9. Example: producer-consumer • Fig.1.12, p.64 • Producer computes x, then append x to the end of buffer b, cycle back. • Consumer removes elements from the top of the buffer, deposits them in y, cycle back.

  10. Semaphores • r: protect the critical section, buffer • ne: “number of empties”, ensuring that producer cannot deposit more than N items (that have not been removed by consumer). • nf: “ number of fulls”, ensuring that consumer does not take from an empty buffer. • nf and ne: unidirectional signaling devices. • nf, a signal generated by producer’s release and sensed by consumer’s request. • ne, a signal generated by consumer’s release and sensed by producer’s request.

  11. 1.9 Region statement • Semaphores provide powerful synchronization constructs. • But they are unstructured and do not enforce a disciplined methodology. • Region statement: protect critical sections, and provide additional testing capabilities.

  12. Example, Fig. 1.13, p. 68 • Problem 1.5 • Resource declaration • r: resource protecting(y1,y2, …,yn) • Region statement • region r when c do S • S does not contain any cooperation statement or other region statement.

  13. Shared variables, must belong to precisely one resource. • c is the guard condition, and S is the body of the region statement. • The only shared variables that may be referenced within c or S must belong to r. • The region statement will be successfully executed, if the condition c be true and no other statement protected by r is currently executing. • See page 67

  14. Comparing Region statements to Semaphores • Region statement comparing to Semaphores: • More structured • More powerful • More expensive implementation

  15. implementation • For a semaphore: • keep track of the current value of the semaphore and • the identity of the processes waiting for it (request). • For a region statement: • keep track of the current status of the resource and • The identities of the waiting processes and • The status of their individual guard conditions.

  16. Synchronization within Selection Statements • In the previous examples: • synchronization statements were essential, • and they appear in the context of concatenation. • It may not be essential, or several synchronizations may be possible • See Fig. 1.14, p. 69 • Producer-consumer with l producers, n consumers and m buffers

  17. 1.10 Model 3: Message-Passing Text • We saw • Diagrams • Shared-variables text • Now • Message-passing text (like CSP)