代写代考 CS 563 Concurrent Programming

CS 563 Concurrent Programming
Lecture 15: Monitors

More structures than semaphores; more control than await History: Hoare’s paper

Copyright By PowCoder代写 加微信 powcoder

OS structure — e.g., Unix
languages — Java and Pthreads library

Basic Concepts
Data encapsulation Implicit mutual exclusion Explicit signaling Monitor structure
monitor name {
declarations of permanent (static)
initialization code — executes first
procedures (methods)

Program Structure
monitor1 … monitorM
process1 … processN
Processes interact indirectly by using the same monitor Processes call monitor procedures
At most one call active in a monitor at a time — by definition Explicit signaling using condition variables

Condition Variables
cond cv; # queue of delayed processes;
# initially empty
wait(cv); # block on cv’s queue AND
# release monitor lock
signal(cv); # awaken one process on cv’s
# queue, if there is one
Questions about signal:
Which one to awaken? Who executes next?

Condition Variables
Signaling strategies:
Signal and continue (SC) — signaler goes next; used in Java, Unix, Pthreads
Signal and wait (SW) — signaled process goes next; used in Hoare’s paper
SW is preemptive; SC is not

Example: Implementing A Semaphore

FIFO Semaphore Using Passing the Condition

Bounded Buffer

Readers/Writers

Interval Timer
Processes call delay (interval)
A clock “process” (interrupt handler) calls tick()

Interval Timer
First approach: awaken all delayed processes and let them check

Interval Timer
Second approach: order delayed processes

Big Picture
Monitors RPC
Busy waiting Semaphores
Message passing Rendezvous

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com