18-SynchronizationProblems - Classic Synchronization...

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

View Full Document Right Arrow Icon
Copyright ©: Nahrstedt, Angrave, Campbell 1 Classic  Synchronization  Problems Producer Consumer Reader-Writer Dining Philosophers 4 Formal Requirements for deadlock
Background image of page 1

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

View Full DocumentRight Arrow Icon
Copyright ©: Nahrstedt, Angrave, Campbell 2 Review - Producer Consumer  using Semaphores bufin bufout #include <errno.h> #include <pthread.h> #include <semaphore.h> static  mytype  buffer[BUFSIZE]; static int bufin = 0; static int bufout = 0; static sem_t semlock;   // =1 static sem_t semitems; // =0 static sem_t semslots;  // =BUFSIZE Note: #semitems+#semslots=BUFSIZE
Background image of page 2
Copyright ©: Nahrstedt, Angrave, Campbell 3 Reader-Writer Difficulty   Allow 1+ Reader in critical section at  same time. Reader Writer Reader OK No Writer NO No
Background image of page 3

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

View Full DocumentRight Arrow Icon
Copyright ©: Nahrstedt, Angrave, Campbell 4 Reader-Writer Problem readers: read data writers: write data Rule: Multiple readers can read the data simultaneously Only one writer can write the data at any time A reader and a writer cannot be in critical section together. Locking table: whether any two can be in the critical section  simultaneously Reader Writer Reader   OK No Writer NO No
Background image of page 4
Copyright ©: Nahrstedt, Angrave, Campbell 5 Reader-Writer Solution? Mutex m, wrt; 
Background image of page 5

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

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

This note was uploaded on 05/04/2008 for the course CS 241 taught by Professor Systemsprogramming during the Spring '08 term at University of Illinois at Urbana–Champaign.

Page1 / 20

18-SynchronizationProblems - Classic Synchronization...

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

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