NT Synchronization Primitives

Slides:



Advertisements
Similar presentations
1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Advertisements

Operating Systems ECE344 Midterm review Ding Yuan
Preemptive Scheduling and Mutual Exclusion with Hardware Support Thomas Plagemann With slides from Otto J. Anshus & Tore Larsen (University of Tromsø)
The OS kernel: Implementing processes and Threads Kernel Definitions and Objects Queue Structures Threads Implementing Processes and Threads Implementing.
The eCos real-time operating system an open source tool to create embedded kernels and applications.
Resource management and Synchronization Akos Ledeczi EECE 354, Fall 2010 Vanderbilt University.
CSCC69: Operating Systems
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.
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.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
Monitors CSCI 444/544 Operating Systems Fall 2008.
02/23/2004CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Synchronization April 14, 2000 Instructor Gary Kimura Slides courtesy of Hank Levy.
1 Concurrency: Deadlock and Starvation Chapter 6.
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.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Introduction to Embedded Systems
Cosc 4740 Chapter 6, Part 3 Process Synchronization.
14 1 Embedded Software Lab. Embedded Software Lab Daejun Park, Eunsoo Park Lecture 8 Synchronization.
CSE451 NT Synchronization Autumn 2002 Gary Kimura Lecture #9 October 18, 2002.
1 Announcements The fixing the bug part of Lab 4’s assignment 2 is now considered extra credit. Comments for the code should be on the parts you wrote.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 5: Process Synchronization.
Kernel Locking Techniques by Robert Love presented by Scott Price.
Lecture 8 Page 1 CS 111 Online Other Important Synchronization Primitives Semaphores Mutexes Monitors.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
CSE 451: Operating Systems Winter 2012 Semaphores and Monitors Mark Zbikowski Gary Kimura.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Monitors and Blocking Synchronization Dalia Cohn Alperovich Based on “The Art of Multiprocessor Programming” by Herlihy & Shavit, chapter 8.
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 Midterm Review.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS3: Concurrency 3.3. Advanced Windows Synchronization.
Windows CE Overview and Scheduling Presented by Dai Kawano.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
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.
CSE 451 Section #3. Questions from Lecture Kinds of threads When threads are used How threads are implemented Scheduling.
CSE 120 Principles of Operating
Chapter 6: Process Synchronization
CS703 – Advanced Operating Systems
Chapter 5: Process Synchronization
Chapter 5: Process Synchronization – Part 3
Auburn University COMP 3500 Introduction to Operating Systems Synchronization: Part 4 Classical Synchronization Problems.
PARALLEL PROGRAM CHALLENGES
Background on the need for Synchronization
Process Synchronization
Other Important Synchronization Primitives
Chapter 5: Process Synchronization
CSE451 Basic Synchronization Spring 2001
CSCI 511 Operating Systems Chapter 5 (Part C) Monitor
Topic 6 (Textbook - Chapter 5) Process Synchronization
Thread Implementations; MUTEX
Threading And Parallel Programming Constructs
UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department
Lecture 2 Part 2 Process Synchronization
Chapter 7: Synchronization Examples
CSE 451: Operating Systems Winter Module 8 Semaphores and Monitors
Thread Implementations; MUTEX
CSE 451: Operating Systems Winter Module 7 Semaphores and Monitors
CSE 153 Design of Operating Systems Winter 19
CSE 153 Design of Operating Systems Winter 2019
CS333 Intro to Operating Systems
NT Executive Resources
Chapter 6: Synchronization Tools
CSE 153 Design of Operating Systems Winter 2019
Process/Thread Synchronization (Part 2)
Akos Ledeczi EECE 6354, Fall 2017 Vanderbilt University
Akos Ledeczi EECE 6354, Fall 2015 Vanderbilt University
Presentation transcript:

NT Synchronization Primitives April 17, 2000 Instructor: Gary Kimura

Kernel Support for Synchronization Spinlocks Interlocked Operations Events Semaphores Mutex Eresource

April 17, 2000 Spinlocks A spinlock is a quick mechanism for acquiring exclusive access to a critical section of code It uses Interrupt Request Levels (IRQL) to disable other code from running Kernel spinlock calls are: KeAcquireSpinLock: Enter critical section KeReleaseSpinLock: Leave critical section On UP systems spinlocks are implemented by raising the Interrupt Request Level On MP systems spinlocks are implemented using a shared variable that contains the owners thread ID Look at handout for MIPS 4000 coding example CSE 451: Introduction to Operating Systems

Interlocked Operations Interlocked operations are atomic operations that can be used to synchronize access to a single variable or as a building block for more complex synchronization routines Some of the supported interlocked operations are InterlockedIncrement InterlockedDecrement InterlockedCompareExchange and there are more

X86 Interlocked Examples lock prefix is MP only April 17, 2000 X86 Interlocked Examples lock prefix is MP only __inline LONG FASTCALL InterlockedIncrement( IN PLONG Addend ) { __asm { mov eax, 1 mov ecx, Addend lock xadd [ecx], eax inc eax } where xadd atomically does temp := eax + [ecx] eax := [ecx] [ecx] := temp __inline LONG FASTCALL InterlockedCompareExchange( IN OUT PLONG Destination, IN LONG Exchange, IN LONG Comperand ) { __asm { mov eax, Comperand mov ecx, Destination mov edx, Exchange lock cmpxchg [ecx], edx } where cmpxchg atomically does if eax == [ecx] [ecx] := edx else eax := [ecx] Xadd does “temp := src + dest; src := dest; dest := temp” Cmpxchg does “if eax == dest then zf := 1; dest := src else zf := 0; eax := dest endif” CSE 451: Introduction to Operating Systems

Events and Semaphores There are two types of events Synchronization events: used to allow one thread at a time to enter a critical region of code Notification events: used to signal all the threads about an event The Semaphore is a plain counted Semaphore Waiting for an event or a semaphore uses the same routines KeWaitForSingleObject KeWaitForMultipleObjects

Events An event variable’s state is either signaled or not-signaled. Threads can wait for an event to become signaled Kernel event calls are KeClearEvent: Event becomes not-signaled KePulseEvent: Atomically signal and then not-signal event KeReadStateEvent: Returns current event state KeResetEvent: Event becomes not-signaled and returns previous state KeSetEvent and KeSetEventBoostPriority: Signal an event and optionally boost the priority of the waiting thread

Semaphores A semaphore variable is just a plain old vanilla counted semaphore, but its implementation shares much of the event logic Kernel semaphore calls are KeReadStateSemaphore: Returns the signal state of the semaphore KeReleaseSemaphore: Takes as input a release count and a priority boost of the newly released threads

April 17, 2000 Wait for routine The kernel supports two major wait routines. These routines can be used by threads to wait for events, semaphores, queues, timers, etc. Kernel wait calls are KeWaitForSingleObject: Wait for one event or semaphore to become signaled KeWaitForMultipleObjects: Wait for one or more events or semaphores (WaitAny or WaitAll) There is an optional timeout on the wait calls that will return from the wait call even if the object is not signaled Some Implementation Details (optional slide) Each Event & Semaphore contains a structure called a dispatcher header that is used to list all those threads that are waiting on the object. A wait call add the dispatcher header to the threads wait list CSE 451: Introduction to Operating Systems

Executive Mutex A mutex looks like a spinlock from the programmers viewpoint but a mutex allow recursion and page faults Operations are ExAcquireFastMutex: Enter critical region ExReleaseFastMutex: Exit critical region ExTryToAcquireFastMutex: Like acquire but return immediately without blocking and indicate if we acquired the mutex The executive mutex is implemented using kernel synchronization events A note regarding Kernel versus Executive routines

Executive Resource The Executive Resource (Eresource) package is used by NT kernel level code to handle the multi-reader/single-writer access to protected data structures. The package exports a typedef called an Eresource Operations are: ExAcquireResourceShared ExAcquireResourceExclusive ExAcquireSharedStarveExclusive ExReleaseResource (ExReleaseResourceForThread) ExConvertExclusiveToShared

Eresource features A resource can be acquired recursively The ownership of a resource is tied to a thread ID The users get to decide whether exclusive waiters starve The package automatically handles priority inversion The routines are implemented using spinlocks, events, and semaphores More details at a later lecture