Win32 Synchronization CS470 -- Spring 2002. Overview Kernel Synchronization - Spinlocks Executive Synchronization - Dispatcher Objects Wait Operations.

Slides:



Advertisements
Similar presentations
Process A process is usually defined as an instance of a running program and consists of two components: A kernel object that the operating system uses.
Advertisements

Lesson 12: Kernel-mode Thread Sync (aka: Why I love Gentoo)
1 Implementations: User-level Kernel-level User-level threads package each u.process defines its own thread policies! flexible mgt, scheduling etc…kernel.
李盈賢.  Start a process with a specific priority class  Methods: 1)Cmd: start /’priority’ ‘filename’ 2)Create a shortcut.
Cpr E 308 Spring 2004 Recap for Midterm Introductory Material What belongs in the OS, what doesn’t? Basic Understanding of Hardware, Memory Hierarchy.
Review: Chapters 1 – Chapter 1: OS is a layer between user and hardware to make life easier for user and use hardware efficiently Control program.
Project 2 教學. Synchronization Functions in Windows HANDLE WINAPI CreateSemaphore ( __in_opt LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, __in LONG lInitialCount,
CS444/CS544 Operating Systems Classic Synchronization Problems 2/28/2007 Prof. Searleman
CS444/CS544 Operating Systems Synchronization 2/28/2006 Prof. Searleman
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
CS 284a, 8 October 1997 Copyright (c) , John Thornley1 CS 284a Lecture Wednesday, 8 October, 1997.
ISP – 3 rd Recitation “The joy of Windows API” Processes Threads Handles Relevant functions A simple code example.
ISP – 7 th Recitation Mid semester!!! Semaphores – reminder Events Code examples.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
CS470 Lab 4 TA Notes. Objective Simulate the activities of a producer and consumer – Page 326 Use thread synchronization to solve the producer-consumer.
CS444/CS544 Operating Systems Synchronization 2/19/2007 Prof. Searleman
ISP – 5 th Recitation Mutexes Code example. Mutex Wikipedia definition: Mutual exclusion (often abbreviated to mutex) algorithms are used in concurrent.
7-1 JMH Associates © 2003, All rights reserved Designing and Developing Reliable, Scaleable Multithreaded Windows Applications Chapter 10 Supplement Advanced.
1 Concurrency: Deadlock and Starvation Chapter 6.
Threads CNS What is a thread?  an independent unit of execution within a process  a "lightweight process"  an independent unit of execution within.
1 Race Conditions/Mutual Exclusion Segment of code of a process where a shared resource is accessed (changing global variables, writing files etc) is called.
Destroy the Castle – Example Instructions. Functional Decomposition2 Lab 1 Activity 1 Build, Run, and Benchmark.
Multi-core Programming Programming with Windows Threads.
计算机系 信息处理实验室 Lecture 4 System Mechanisms (2)
2.3 InterProcess Communication (IPC)
CSE451 NT Synchronization Autumn 2002 Gary Kimura Lecture #9 October 18, 2002.
1-1 © 2004 JMH Associates. All rights reserved. Windows Application Development Chapter 7 Windows Thread Management.
Threads and Thread Synchronization Advanced Windows Programming Series 1.
Win32 Programming Lesson 7: Kernel Objects. Abstract  Many of the concepts we’ll look at today won’t make complete sense until you use them  However,
1 Confidential Enterprise Solutions Group Process and Threads.
Windows thread programming
Multithreaded Programming With the Win32 API Andrew Tucker Andrew Tucker Debugger Development Lead March 13, 1998.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS3: Concurrency 3.4. Windows APIs for Synchronization.
NT Kernel CS Spring Overview Interrupts and Exceptions: Trap Handler Interrupt Request Levels and IRT DPC’s, and APC’s System Service Dispatching.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Programming with Windows* Threads Intel Software College.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Windows 2000 Michael Blinn Ben Hejl Jane McHugh Matthew VanMater.
Windows Thread Management

CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
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.
Managing Processors Jeff Chase Duke University. The story so far: protected CPU mode user mode kernel mode kernel “top half” kernel “bottom half” (interrupt.
3/17/2016cse synchronization-p2 © Perkins, DW Johnson and University of Washington1 Synchronization Part 2 CSE 410, Spring 2008 Computer.
Window Threads Chapter 7 Windows Thread Management.
CSE 120 Principles of Operating
CS703 – Advanced Operating Systems
Operating Systems: A Modern Perspective, Chapter 6
Threads and Thread Synchronization
Chapter 3: Windows7 Part 2.
Chapter 3: Windows7 Part 2.
Waiting and Synchronization
Chapter 05. Multithread.
UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department
Lecture 2 Part 2 Process Synchronization
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/49.
NT Synchronization Primitives
CSE 153 Design of Operating Systems Winter 19
CS333 Intro to Operating Systems
Chapter 6: Synchronization Tools
26.
Outline Process Management Process manager Hardware process
Process Synchronization
Window Application Development
CSE 153 Design of Operating Systems Winter 2019
Process Synchronization
Michael Blinn Ben Hejl Jane McHugh Matthew VanMater
Chapter 3: Process Management
Presentation transcript:

Win32 Synchronization CS Spring 2002

Overview Kernel Synchronization - Spinlocks Executive Synchronization - Dispatcher Objects Wait Operations Dispatcher Objects - Events, Semaphores, Mutex objects, Waitable Timers

Kernel Synchronization Manipulating IRQL selectively disables interrupts -- controls context switching IRQL only works on a single processor Spinlocks, based e.g. on test & set instructions, work for multiprocessors Busy-wait wastes cycles - so holder is never preempted, is not allowed to cause page faults, do system calls, cause interrupts or exceptions, etc.

Executive Synchronization Executive also uses spinlocks Also uses dispatcher objects Dispatcher objects also available to user programs - Win32 calls include WaitForSingleObject and WaitForMultipleObjects applicable to processes, threads, events, semaphores, mutex objects, waitable timers, file objects, etc.

Thread Dispatcher States Terminated-4 Ready-1 Standby-3 Transition-6 Waiting-5 Running-2 Initialized-0 Create Destroy Done Wait for Object Reinitialize Preempt Select Context-Switch Need Resource Get resource All Set Ready to run

Dispatcher Database Thread 1 Thread 2 Thread 3 Thread 4 Process 5 Timer 0 KWAIT_BLOCKS Dispatchers

Wait Operations (1 of 2) DWORD WaitForSingleObjectEx( HANDLE hHandle, DWORD dwMilliseconds BOOL bAlertable); Returns WAIT_OBJECT_0 (zero), WAIT_TIMEOUT, WAIT_FAILED, or WAIT_IO_COMPLETION If object non-signaled, block thread. When signaled, one or more threads are readied - can change state of object.

Wait Operations (2 of 2) DWORD WaitForMultipleObjectsEx( DWORD nCount, CONST HANDLE *lpHandles BOOL fWaitAll, DWORD dwMilliseconds, BOOL bAlertable); WAIT_OBJECT_0 to WAIT_OBJECT_n-1 to specify first signaled handle (if fWaitAll if false).

Events (1 of 2) HANDLE CreateEvent ( LPSECURITY_ATTRIBUTES lpSA, BOOL bManualReset, BOOL bInitialState, LPCTSTR lpName); HANDLE OpenEvent ( DWORD dwDesiredAccess, BOOL bInheritHandle, LPCTSTR lpName);

Events (2 of 2) BOOL SetEvent ( HANDLE hEvent ); BOOL ResetEvent ( HANDLE hEvent ); BOOL PulseEvent ( HANDLE hEvent ); manual-reset versus auto-reset events setting versus pulsing CloseHandle used to close events

Mutual Exclusion (Events) Initialization: hEvent = CreateEvent( NULL, FALSE, TRUE, NULL); Critical Section Entry: WaitForSingleObjectEx( hEvent, INFINITE, FALSE); Critical Section Exit: SetEvent(hEvent);

Semaphores (1 of 2) HANDLE CreateSemaphore ( LPSECURITY_ATTRIBUTES lpSA, LONG lInitialCount, LONG lMaximumCount, LPCTSTR lpName ); HANDLE OpenSemaphore ( DWORD dwDesiredAccess, BOOL bInheritHandle, LPCTSTR lpName );

Semaphores (2 of 2) BOOL ReleaseSemaphore ( HANDLE hSemaphore, LONG lReleaseCount, LPLONG lpPreviousCount ); lReleaseCount is 1 to release semaphore or larger in order to set an initial value. CloseHandle to close semaphore handle

Mutual Exclusion (Semaphore) Initialization: hSemaphore = CreateSemaphore( NULL, 1, 1, NULL); Critical Section Entry: WaitForSingleObjectEx( hSemaphore, INFINITE, FALSE); Critical Section Exit: ReleaseSemaphore( hSemaphore, 1, &previous);

Mutex Objects (1 of 2) HANDLE CreateMutex ( LPSECURITY_ATTRIBUTES lpSA, BOOL bInitialOwner, LPCTSTR lpName ); HANDLE OpenMutex ( DWORD dwDesiredAccess, BOOL bInheritHandle, LPCTSTR lpName );

Mutex Objects (2 of 2) BOOL ReleaseMutex ( HANDLE hMutex ); Owner can make additional calls Wait calls without blocking, but must call ReleaseMutex the same number of times. Use CloseHandle to close mutex handles.

Mutual Exclusion (Mutex) Initialization: hMutex = CreateMutex( NULL, FALSE, NULL); Critical Section Entry: WaitForSingleObject( hMutex, INFINITE, FALSE); Critical Section Exit: ReleaseMutex(hMutex);

Waitable Timers (1 of 2) HANDLE CreateWaitableTimer ( LPSECURITY_ATTRIBUTES lpSA, BOOL bManualReset, LPCTSTR lpTimerName ); HANDLE OpenWaitableTimer ( DWORD dwDesiredAccess, BOOL bInheritHandle, LPCTSTR lpTimerName );

Waitable Timers (2 of 2) BOOL SetWaitableTimer ( HANDLE hTimer, const LARGE_INTEGER *pDueTime, LONG lPeriod, PTIMERAPCROUTINE pfnCompletionRoutine, LPVOID lpArgToCompletionRoutine, BOOL fResume ); BOOL CancelWaitableTimer (HANDLE);

Mutual Exclusion (Timer) 1 of 2 Initialization: LARGE_INTEGER dueTime = {-1, -1}; hTimer = (HANDLE) CreateWaitableTimer( NULL, FALSE, NULL); SetWaitableTimer( hTimer, &dueTime, 0, NULL, NULL, FALSE);

Mutual Exclusion (Timer) 2 of 2 Critical Section Entry: WaitForSingleObjectEx(hTimer, INFINITE, FALSE); Critical Section Exit: LARGE_INTEGER dueTime = {-1, -1}; SetWaitableTimer(hTimer, &dueTime, 0, NULL, NULL, FALSE);