Preemption Set timer interrupts But now, must synchronize Two tools:

Slides:



Advertisements
Similar presentations
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Advertisements

Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
CSE 451: Operating Systems Section 6 Project 2b; Midterm Review.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
1 CSE451 – Section 5. 2 Reminders/Overview Rest of project 2 due Monday February 13 Turnin code + writeup Midterm Wednesday the 8th Today: Project 2 parts.
5.6.2 Thread Synchronization with Semaphores Semaphores can be used to notify other threads that events have occurred –Producer-consumer relationship Producer.
CS533 Concepts of Operating Systems Class 3 Monitors.
CPS110: Implementing threads/locks on a uni-processor Landon Cox.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Computer Science 162 Discussion Section Week 3. Agenda Project 1 released! Locks, Semaphores, and condition variables Producer-consumer – Example (locks,
02/19/2007CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Programming Network Servers Topic 6, Chapters 21, 22 Network Programming Kansas State University at Salina.
Multithreaded Web Server.
Nachos Phase 1 Code -Hints and Comments
Not Another Completely Heuristic Operating System
Cosc 4740 Chapter 6, Part 3 Process Synchronization.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Process Synchronization I Nov 27, 2007 CPE Operating Systems
Threads & Networking C# offers facilities for multi threading and network programming an application roughly corresponds to a process, handled by the OS.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 5: Process Synchronization.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Discussion Week 2 TA: Kyle Dewey. Overview Concurrency Process level Thread level MIPS - switch.s Project #1.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
CSE 153 Design of Operating Systems Winter 2015 Lecture 5: Synchronization.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 22 Semaphores Classic.
Implementing Lock. From the Previous Lecture  The “too much milk” example shows that writing concurrent programs directly with load and store instructions.
CS 153 Design of Operating Systems Winter 2016 Lecture 7: Synchronization.
CSE 451: Operating Systems Section 7: Project 2b; Virtual Memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
CSE 451: Operating Systems Section 6 Project 2b. Midterm  Scores will be on Catalyst and midterms were handed back on Friday(?) in class  Talk to Ed,
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
Web Server Architecture Client Main Thread for(j=0;j
1 Introduction to Threads Race Conditions. 2 Process Address Space Revisited Code Data OS Stack (a)Process with Single Thread (b) Process with Two Threads.
Thread Synchronization
Chapter 6: Process Synchronization
CS703 – Advanced Operating Systems
PARALLEL PROGRAM CHALLENGES
Today’s topics Project 2 - Work on CEREAL - Due: Oct 10, :00 pm
Interprocess Communication (3)
January 29, 2004 Adrienne Noble
Winter 2k7 Kurtis Heimerl Aaron Kimball
CS533 Concepts of Operating Systems Class 3
Chapter 5: Process Synchronization
Semaphore Originally called P() and V() wait (S) { while S <= 0
CSE451 – Section 6.
UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department
CSE 451 Autumn 2003 Section 3 October 16.
Implementing Mutual Exclusion
CSE451 – Section 5.
CS533 Concepts of Operating Systems Class 3
Implementing Mutual Exclusion
First slide Rest of project 2 due next Friday Today:
Reminders Homework 4 due next Friday Rest of project 2 due next Friday
Why Threads Are A Bad Idea (for most purposes)
CSE 153 Design of Operating Systems Winter 19
CSE 153 Design of Operating Systems Winter 2019
Chapter 6: Synchronization Tools
Project 2, part 4 - web server
CSE 451 Section 1/27/2000.
Why Threads Are A Bad Idea (for most purposes)
Why Threads Are A Bad Idea (for most purposes)
Monitors and Inter-Process Communication
Synchronization CSE 2431: Introduction to Operating Systems
Presentation transcript:

Preemption Set timer interrupts But now, must synchronize Two tools: Switch threads on interrupt Same idea as other switches But now, must synchronize Two tools: Enable/disable interrupts test_and_set(), clear()

Preemption (cont’d) Enable/disable interrupts to synchronize thread code int old = splx(HIGH) // disable splx(old) // re-enable Use test_and_set for other stuff Why not disable interrupts?

Multi-thread web server (1) web/sioux.c – singlethreaded web server Read in command line args, run the web server loop web/sioux_run.c – the webserver loop Open a socket to listen for connections (listen) Wait for a connection (accept) Handle it Parse the HTTP request Find and read the requested file (www root is ./docs) Send the file back Close the connection web/web_queue.c – an empty file for your use

Multi-thread web server (2) Make the web server multithreaded Create a thread pool A bunch of threads waiting for work Number of threads = command-line arg Wait for a connection Find an available thread to handle connection Current request waits if all threads busy Once a thread grabs onto connection, it uses the same processing code as before

Multi-thread web server (3) Each connection is identified by a socket returned by accept Which is just an int Simple management of connections among threads Threads should sleep while waiting for a new connection Condition variables are perfect for this Don’t forget to protect any global variables Use part 2 mutexes, CVs Develop + test with pthreads initially Mostly modify sioux_run.c and/or your own files Stick to the sthread.h interface!

Semaphores (1) Where are critical sections? wait(semaphore *S) { S->value--; if (S->value < 0) { add to S->list; block() } signal(semaphore *S) { S->value++; if (S->value <= 0) { remove P from S->list; wakeup(P); Where are critical sections?

Semaphores (2) wait(semaphore *S) { while (TestAndSet(S->guard)) ; S->value--; if (S->value < 0) { add to S->list; block() } S->guard = false What’s wrong with this?

Semaphores (3) wait(semaphore *S) { while (TestAndSet(S->guard)) ; S->value--; if (S->value < 0) { add to S->list; S->guard = false block() } OK?

Semaphores (4) wait(semaphore *S) { while (TestAndSet(S->guard)) ; S->value--; if (S->value < 0) { add to S->list; S->guard = false block() } S->guard = false; No, really, OK?

Semaphores (5) wait(semaphore *S) { while (TestAndSet(S->guard)) ; S->value--; if (S->value < 0) { add to S->list; S->guard = false block() } else { S->guard = false; }

Alarm clock (1) monitor alarm { condition alarm; wakeme(int num_ticks) { ... alarm.wait(); } tick() { alarm.signal(); }

Alarm clock (2) monitor alarm { condition alarm; wakeme(int num_ticks) { ... alarm.wait(); } tick() { alarm.broadcast(); }

Alarm clock (3) monitor alarm { sorted_list list; int time = 0; wake_me(int num_ticks) { c = new condition; list->insert ( time + num_ticks, c); c->wait(); }

Alarm clock(4) monitor alarm { ... tick() { time++; for (head()->time == time) c->signal(); }