transp-language-mech1

transp-language-mech1 - Language Mechanisms for...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Language Mechanisms for Synchronization Additional mechanisms are needed for large and reliable systems. Concurrent threads and processes are more complex as a result of more interaction, and time dependent errors are more likely to occur. Synchronization methods can be integrated into programming languages to ensure that correctness is supported independent of the underlying hardware. Language constructs used for the implementation of synchronization support include: data type abstraction, control structure, program structure, procedure call, and communication such as message passing. The following table shows examples of synchronization methods and their use of language facilities. Synchronization Method Language Facilities Semaphore Shared variable and system call Monitor Data type abstraction Serializer Data type abstraction and control structure Path expression Data type and program structure Rendezvous Procedure call and message passing Monitor: A Data Type Abstraction Approach A monitor is an object model concept and has a syntactic structure similar to a user-defined data type. A monitor provides support for the definition of shared objects (resources) and the scheduling of access to these objects in a multiprogramming environment. One significant semantic assumption in monitor is that only one instantiation of a monitor object can be active at any time, which provides the implicit support of mutual exclusion for access to the monitor object. Once in a monitor procedure, the activities that a process may perform are coordinated through conditional variables and the wait , signal and queue operations on these variables. Structure of a Monitor < monitor-name >: monitor Declaration of data local to the monitor L procedure < procedure-name > (< formal parameters >) begin procedure-body end other procedures L begin initialization of local data of the monitor end
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
A monitor solution for the producer/consumer problem bounded-buffer : monitor var B : array [0. .N-1] of if message ; in, out : 0. .N-1; nonfull, nonempty : condition ; count: 0. .N; procedure place( x : message ) begin if count = N then nonfull. wait ; B[in] := x; in := (in + 1) mod N; count := count + 1; nonempty. signal ; end procedure remove( var x : message ) begin if count = 0 then nonempty.wait; x := B[out]; out := (out + 1) mod N; count := count - 1; nonfull. signal ; end begin in := 0; out := 0; count := 0; end A monitor solution to the weak reader preference problem readers-writers : monitor var readercount : integer ; busy : Boolean ; OKtoread, OKtowrite : condition ; procedure startread begin if busy then OKtoread. wait ; readercount := readercount + 1; OKtoread. signal ; (*Once one reader starts, a chain reaction enables all waiting readers to follow. *) end procedure endread begin readercount := readercount – 1; if readercount = 0 then OKtowrite. signal ; end
Background image of page 2
procedure startwrite begin if busy or readercount 0 then OKtowrtie. wait ; busy := true ; end procedure endwrite
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

transp-language-mech1 - Language Mechanisms for...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online