CS 241 Spring 2007: System Programming Midterm Review - Reader-Writer Problem, Study notes of Computer Science

A set of lecture notes for a university course, cs 241, focusing on the topic of the reader-writer problem in system programming. The notes cover the classic synchronization problem, the first reader-writer problem solution, and midterm review topics. Students are encouraged to review lecture materials, quizzes, and homework solutions for the exam.

Typology: Study notes

Pre 2010

Uploaded on 03/16/2009

koofers-user-2n3
koofers-user-2n3 🇺🇸

10 documents

1 / 18

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 241 Spring 2007
System Programming
1
Classic Synchronization Problems
(Reader-Writer Problem)
Midterm Review Topics
Lecture 19
Klara Nahrstedt
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download CS 241 Spring 2007: System Programming Midterm Review - Reader-Writer Problem and more Study notes Computer Science in PDF only on Docsity!

CS 241 Spring 2007System Programming

Classic Synchronization Problems (Reader-Writer Problem) Midterm Review Topics

Lecture 19 Klara Nahrstedt

CS241 Administrative

†

Read Chapter 5.6 in Stallings

†

Homework 1 due 3/2 4pm in Anda Ohlsson’sOffice

†

MIDTERM – MONDAY, March 5, 11am (willtalk about Midterm at the end of lecture)

First 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 in critical section together.

Locking table: whether any two can be in the critical sectionsimultaneously

Reader

Writer

Reader

OK

No

Writer

NO

No

First Readers-Writers Problem (Readers have priority) Let processes reading do so concurrently Let processes writing do so one at a time Introduce semaphores Semaphore mutex = 1; Semaphore wrt = 1; int readc = 0; /* reader counter */

First Reader-Writer Solution Does it work? What if?Problem with this solutionMutex m, wrt;int readcount;

// shared and initialized to 0

// Writer

// Reader

Lock(&m);

readcount:=readcount+1;

Lock(&wrt);

if (readcount == 1) lock(&wrt);

......

unlock(&m);

writing performed

....

.....

reading performedlock(&m);

Lock(&wrt);

readcount:=readcount-1;if (readcount == 0) unlock(&wrt);

Unlock(&m);

Midterm Review †

Review^ „

Lecture Notes

„

All quizzes until today †

SMP Quizzes and Regular Quizzes

„

Review homework 1 solutions

„

Review Stallings and R&R book material

†

Midterm

  • Monday 11-11:50am, 1404 SC

†

Review Session

  • Sunday 2-3:30pm in 1404 SC

„

You need to bring questions, TAs will respond

†

Midterm^ „

closed book, closed notes,

„

NO calculator or other calculating electronic devices

„

No cell-phones

Topics: Processes †

Chapter 3.1-3.4 (Stallings)

†

Chapter 2 and 3 (R&R)

†

Keywords need to know „

What is process?

„

What is the difference between process and program?

„

What is the program image layout?

„

Understand argument arrays

„

What does it mean to have a thread-safe function?

„

What is the difference between static and dynamic variables?

„

What are the major process states?

„

What is the difference between dispatcher and scheduler?

„

What is PCB?

„

What happens when process switches from running to readystate?

„

What is process chain, process fan?

Topics: Threads †

Chapter 12.1-12.5 (R&R)

†

Chapter 4.1, 4.5 (Stallings)

†

Keywords need to know^ „

What is the difference between processes andthreads?

„

What is the difference between user-level threadsand kernel-level threads?

„

Detaching and joining threads

„

What happens if you if you call exit(1) in a thread?

„

What is a graceful way to exit a thread withoutcausing process termination?

Topics: Thread Synchronization †

Chapter 13.1-13.2 (R&R)

†

Keywords to know^ „

What are mutex locks?

„

How do you initialize mutex locks?

„

When would you use mutex instead of countingsemaphore?

„

When would you use counting semaphore instead ofmutex?

„

Are mutex functions interrupted by signals?

Topics: Scheduling †

Chapter 9.1-9.2 Scheduling (Stallings)

†

Keywords need to know^ „

Scheduling policies

„

FCFC, SJF, Round Robin, Priority Scheduling

„

Preemptive vs. Non-Preemptive Scheduling

„

Queues in Process management – what is readyqueue? How are process states related to processmanagement queues?

„

What is average waiting time?

„

What is the difference between process waiting timeand turn-around time?

Topics: Timers †

Chapter 9.1-9.3 (R&R)

†

Keywords need to know^ „

Understand what the various time functions are for

„

Gettimeofday

„

Understand the different clock resolutions

„

Sleep function

„

What are time intervals? What are they great for?

Topics: Classical Sync Problems †

Chapter 5.3 and 6.6 (Stallings )

†

Keywords need to know^ „

What is the producer-consumer problem?

„

What are the various semaphores in theproducer/consumer solution for?

„

What is the dining philosopher problem?

„

What is the danger of a simple solution for diningphilosopher problem?