CSE 451 Section #3. Questions from Lecture Kinds of threads When threads are used How threads are implemented Scheduling.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Operating Systems Lecture 7.
Operating Systems Part III: Process Management (Process Synchronization)
CAS3SH3 Midterm Review. The midterm 50 min, Friday, Feb 27 th Materials through CPU scheduling closed book, closed note Types of questions: True & False,
Global Environment Model. MUTUAL EXCLUSION PROBLEM The operations used by processes to access to common resources (critical sections) must be mutually.
Ch 7 B.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 6: Process Synchronization
Background Concurrent access to shared data can lead to inconsistencies Maintaining data consistency among cooperating processes is critical What is wrong.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
Interprocess Communication
Operating Systems CMPSC 473 Mutual Exclusion Lecture 13: October 12, 2010 Instructor: Bhuvan Urgaonkar.
Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 91 Today’s class Mutual exclusion and synchronization 
CSE 451: Operating Systems Section 6 Project 2b; Midterm Review.
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
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 Semaphores Special variable called a semaphore is used for signaling If a process is waiting for a signal, it is suspended until that signal is sent.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
Semaphores, mutexes and condition variables. semaphores Two types – Binary – 0 or 1 – Counting 0 to n Wait – decrements > 0 forces a wait Post or signal.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Discussion Week 3 TA: Kyle Dewey. Overview Concurrency overview Synchronization primitives Semaphores Locks Conditions Project #1.
Nachos Phase 1 Code -Hints and Comments
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
CSE451 NT Synchronization Autumn 2002 Gary Kimura Lecture #9 October 18, 2002.
1 Lecture 8: Concurrency: Mutual Exclusion and Synchronization(cont.) Advanced Operating System Fall 2009.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
CSCI1600: Embedded and Real Time Software Lecture 17: Concurrent Programming Steven Reiss, Fall 2015.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
CSE 451 Section 4. 2 Synchronization High-level Monitors Java synchronized method OS-level support Special variables – mutex, semaphor, condition var.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion Mutexes, Semaphores.
CS162 Section 2. True/False A thread needs to own a semaphore, meaning the thread has called semaphore.P(), before it can call semaphore.V() False: Any.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Section 5 Synchronization primitives (Many slides taken from Winter 2006)
CS703 - Advanced Operating Systems
PROCESS MANAGEMENT IN MACH
CS703 – Advanced Operating Systems
COT 4600 Operating Systems Fall 2009
CS533 Concepts of Operating Systems Class 3
CSE 120 Principles of Operating
Lecture 13: Producer-Consumer and Semaphores
Condition Variables and Producer/Consumer
Semaphore Originally called P() and V() wait (S) { while S <= 0
Lecture 2 Part 2 Process Synchronization
Chapter 7: Synchronization Examples
Chapter 30 Condition Variables
CSE 451 Autumn 2003 Section 3 October 16.
CSCI1600: Embedded and Real Time Software
CS533 Concepts of Operating Systems Class 3
CSE 451: Operating Systems Autumn Lecture 8 Semaphores and Monitors
NT Synchronization Primitives
Lecture 13: Producer-Consumer and Semaphores
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
CSE 153 Design of Operating Systems Winter 19
CSE 153 Design of Operating Systems Winter 2019
CS333 Intro to Operating Systems
CSCI1600: Embedded and Real Time Software
CSE 451 Section 1/27/2000.
Monitors and Inter-Process Communication
EECE.4810/EECE.5730 Operating Systems
Process/Thread Synchronization (Part 2)
CSE 542: Operating Systems
Don Porter Portions courtesy Emmett Witchel
CSE 542: Operating Systems
Presentation transcript:

CSE 451 Section #3

Questions from Lecture Kinds of threads When threads are used How threads are implemented Scheduling

Homework Mean – 22.8/25 Style –Always explain your answers. Just an answer with not explanation is only worth 50% –Try to be concise. A short correct answer is better than a long correct answer –Please staple – if we lose a page because its not stapled, that is your problem.

Homework Confusions 1.4 – security issues with time sharing 1.x – is efficiency important 2.1 – prefetching 2.3 – traps vs interrupts 2.8 – what operations must be restricted? 3.7 – what is a system call? 3.10 – what is the benefit of a VM?

Project Implement: –Condition Variables –Sending / receiving messages –Thread::Join() –Priority scheduling –Whale Mating

What we give you Threads with Fork() Semaphores Sample code for a list with synchronized access –In synchlist.cc –N.b.: locks not implemented yet

What you need to implement In Synch.cc: –Condition class How: –Look at implementation of semaphores –Implement using a similar style –Use semaphores as part of implementation

Example: p() // disable interrupts IntStatus oldLevel = interrupt->SetLevel(IntOff); // semaphore not available while (value == 0) { // so go to sleep queue->Append((void *)currentThread); currentThread->Sleep(); } // semaphore available, consume its value value--; // re-enable interrupts (void) interrupt->SetLevel(oldLevel);

Condition Variables Three operations –Wait –Signal –Broadcast

Condition Variable Usage Define the condition you are synchronizing Hold the lock –Test the condition –If false, release lock and wait for signal –When signaled, grab lock and repeat –If true, execute code & release lock

Signaling a Condition Variable Signal – wake up one waiter Broadcast – wake up all waiters –Useful if they have different conditions –Useful for reader/writer locks

Sample Code Void Consume(LIST_TYPE List) { LIST_ELEM Next; List.mutex.lock() While (List.head == NULL) do Cond_wait(ListNonEmpty, List.mutex); Next = List.Head; List.Head = List.Head.Next; List.mutex.unlock(); }

Sample Code Void Produce(LIST_TYPE List, LIST_ELEM Next) { List.mutex.lock(); Next.next = List.Head; List.head = Next; Cond_Signal(ListNonEmpty, List.Mutex) List.mutex.unlock(); }

How Condition Variables Work Wait: add to waiting list, waiting on variable Signal: remove first element of waiting list, move to ready list, waiting on Lock. Broadcast: remove one element of waiting list, move to ready list. Make all other elements wait on the Lock instead of the variable.

Sending / Receiving Messages Mailboxes – can hold at most one message Reader blocks until there is a message in it Sender blocks until there are no messages in it If there are multiple senders / readers, they queue Treat as bounded buffer with bound = 1

Mail Boxes What is needed to implement this? –A queue? –A condition variable? –A mutex?

Thread Join Allows a thread to wait for another one to terminate Does not return the return value from forked thread Need to modify ThreadFinish to signal any waiters on Join() May be multiple callers to Join

Priority Scheduling Modify ready list to handle priority TimerInterruptHandler calls Interrupt::YieldOnReturn –Calls CurrentThread->Yield Enable timer interrupts with “nachos –rs #” –To make non random, modify system.cc to pass “false” to “new timer(…)”

How are Threads Used Two common paradigms: –Thread pools –Worker Threads

Thread Pools Used in server applications: –Web servers –File servers –RPC servers Have a list of threads –On a new request, hand to a thread and signal it to start –If no threads ready, either queue request or create a new thread –Often have high/low thresholds for # of threads

Worker Threads Used to partition work into multiple parallel pieces Example: web page –Pull basic data –Pull personalization data –Pull advertising –All 3 threads execute simultaneously

Worker Threads (2) Fork multiple threads, one for each part Signal when all complete: –Use a condition variable, basic thread checks all three when done –Use a sempaphore – how? –Use a mutex Have a counter…

Other kinds of synchronization Hardware based: –Atomic increment Good for reference counts lock xadd [ecx],eax –Atomic exchange Good for list manipulation mov eax, [ecx] ; get operand value Ixchg: cmpxchg [ecx], edx ; compare and swap jnz Ixchg ; if nz, exchange failed