Concurrent Processes and Programming - Notes | COP 5615, Study notes of Computer Science

Material Type: Notes; Professor: Newman; Class: DIST OPER SYS PRINC; Subject: COMPUTER PROGRAMMING; University: University of Florida; Term: Fall 2009;

Typology: Study notes

Pre 2010

Uploaded on 09/17/2009

koofers-user-b6c
koofers-user-b6c 🇺🇸

10 documents

1 / 21

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CHAPTER 3: CONCURRENT PROCESSES
AND PROGRAMMING
Chapter outline
Thread implementations
Process models
The client/server model
Time services
Language constructs for synchronization
Concurrent programming systems
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15

Partial preview of the text

Download Concurrent Processes and Programming - Notes | COP 5615 and more Study notes Computer Science in PDF only on Docsity!

CHAPTER 3: CONCURRENT PROCESSES

AND PROGRAMMING

Chapter outline

  • Thread implementations
  • Process models
  • The client/server model
  • Time services
  • Language constructs for synchronization
  • Concurrent programming systems

Processes and threads

  • Processes: separate logical address space
  • Threads: common logical address space

Major Issues

  • Process/thread creation
  • Light weight context switching
  • Blocking and scheduling

Thread implementations

  • User space: simple but non-preemptable
  • Kernel space: efficient but not portable

Solaris thread implementation

multiple processor system

LWP LWP LWP LWP

Heavy-weight process Heavy-weight process

User space threads

Light-weight processes

Kernel space threads

Process models

Synchronous Process, Asynchronous Communication, Time-Space

Graph representations

precedence relations

communication channels

one - way

client / server

peer

Synchronous process graph (^) communication scenarios

Asynchronous process graph and

Time services

  • time and timer
  • physical and logical clocks

Physical clock

A distributed time service architecture

TS

TS TS TC

TC

Distributed Time Service

Client Time Clerks

T ime Servers

External UTC Sources

Time Discrepancies

UTC 5

discarded new UTC

UTC 4

UTC 3

UTC 2

UTC 1

Lamport Logical Clock

The happens-before relationship: →

  1. If a → b within a same process then C(a) < C(b).
  2. If a is the sending event of Pi and b is the corresponding receiving event of Pj , then a → b and Ci(a) < Cj (b).

For it to be possible for a to have an influence on b, then a → b must be true.

Implementation:

C(b) = C(a) + d and Cj (b) = max(T Sa + d, Cj (b)), where T Sa is the timestamp of the sending event and d is a positive number.

d = 1

a, b, c,

d, e, f,

g, h,

So, a → b =⇒ C(a) < C(b), but C(a) < C(b) =/⇒ a → b.

Matrix Logical Clock

MCi represents Pi’s knowledge of its local events (MCi[i, i]), its knowledge of the events that Pj knows about (MCi[i, j]), and its knowledge of Pj ’s knowledge of events at Pk (MCi[j, k]). MCi[i, i] = MCi[i, i] + d – Pi updates local event counter on send

When Pj receives a message from Pi with timestamp T S, MCj [j, l] = max(MCj [j, l], T Si[i, l]) : l = 1..n update vector clock, and

MCj [k, l] = max(MCj [k, l], T Si[k, l]) : k = 1..n, l = 1..n update Pk’s knowledge of Pl’s counter

i

i

i,i

j j

Pi’s Vector Clock

Pj’s Vector Clock

k Pi’s knowledge of Pk’s Vector Clock k Pj’s knowledge of Pk’s Vector Clock

i

TS = MCi MCj

Pj’s knowledge of Pi’s Vector Clock

Pi’s knowledge of Pj’s knowledge of Pi’s Lamport Clock

elementwise max merge

Concurrent languages

  • Specification of concurrent activities
  • Synchronization of processes
  • Interprocess communication
  • Nonderterministic execution of processes

Language constructs

  • Program structure
  • Data structure
  • Control structure
  • Procedure and system call
  • Input and output
  • Assignment

Example: the Reader/Writer Problems synchronization + concurrency

Basics

  • if DB empty, allow anyone in
  • if reader in DB, writer not allowed in
  • if writer in DB, nobody allowed in

Write Lock

Lock Held

Read Lock Write Lock

Read Lock

Requested

Lock

Variations

  • reader preference Allow a reader in if other readers are in
  • strong reader preference Allow readers in when writer leaves
  • weak reader preference When writer leaves, select a process at random
  • weaker reader preference Allow a writer in when writer leaves
  • writer preference Do not allow readers in if writer is waiting

Semaphore solution to the weak reader preference problem

var mutex=1, db=1: semaphore; rc=0: integer

reader processes writer processes

do (forever) do (forever) BEGIN BEGIN

otherStuff() otherStuff()

P(mutex) rc := rc + 1 if rc = 1 then P(db) P(db) V(mutex)

read database write database

P(mutex) rc := rc - if rc = 0 then V(db) V(db) V(mutex)

END END

CCR solution

var db: shared; rc: integer;

reader processes writer processes

region db begin rc := rc + 1 end; region db when rc = 0 read database begin write dat abase end region db begin rc := rc - 1 end;

Serializer solution

rw : serializer var readq, writeq: queue; rcrowd, wcrowd: crowd;

procedure read begin enqueue(readq) until empty(wcrowd); joincrowd(rcrowd) then begin read database end; end

procedure write begin enqueue(writeq) until (empty(wcrowd) and empty(rcrowd)); joincrowd(wcrowd) then begin write database end; end

Path Expression solution

path 1:([read],write) end

Message Passing Synchronization

  • Asynchronous: non-blocking send, blocking receive
  • Synchronous: blocking send, blocking receive

Mutual exclusion using asyn. msg. passing

process Pi channel server process Pj begin begin begin receive(channel) create channel receive(channel) critical section send(channel) critical section send(channel) manage channel send(channel) end end end

Mutual exclusion using syn. msg. passing

process Pi semaphore server process Pj begin loop begin send(sem,msg) receive(pid,msg) send(sem,msg) critical section send(pid,msg) critical section receive(sem,msg) end receive(sem,msg) end end

Concurrent Programming Languages

A taxonomy

synchronization and communication mechanisms

shared variable message passing

type abstraction

control structure

program structure

monitor CCR Path

asynchronous

direct process naming

procedure naming

indirect port/mailbox naming

synchronous

request / reply (passive)

rendezvous (active)

process naming

procedure naming

process naming

procedure naming

RPC

asynchronous RPC

rendezvous form of RPC

Concurrent Pascal

Path Pascal

PLITS Gypsy CSP ADA Argus (^) DP DP Concurrent C

SR

SR

X- window sockets

embedded in many OS

DP none

asymmetric symmetric

Coordination languages

  • OCCAM: based on CSP process model, use PAR, ALT, and SEQ con- structors, use explict global links for communication.
  • SR: based on resource (object) model, use synchronous CALL and asyn- chronous SEND and rendezvous IN, use capability for channel naming.
  • LINDA: based on distributed data structure model, use tuples to repre- sent both process and object, use blocking IN and RD and non-blocking OUT for communication.

concurrent programming language concurrent programming language concurrent programming paradigm

OCCAM

SR

LINDA

processes

resources

distributed data structures

static global channels dynamic capabilities associative tags

System Object model Channel naming