MS Windows Concurrency Mechanisms Prepared By SUFIAN MUSSQAA AL-MAJMAIE

Similar documents
CS420: Operating Systems. Process Synchronization

Chapter 6: Synchronization. Operating System Concepts 8 th Edition,

Mutual Exclusion and Synchronization

Process Synchronization

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition

Synchronization. Race Condition. The Critical-Section Problem Solution. The Synchronization Problem. Typical Process P i. Peterson s Solution

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6.

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

Chapter 6: Process Synchronization

Concurrency, Mutual Exclusion and Synchronization C H A P T E R 5

Process Synchronisation (contd.) Operating Systems. Autumn CS4023

Chapter 7: Process Synchronization!

Synchronization Principles

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition,

Process Synchronization

Lecture 6. Process Synchronization

Process Synchronization

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Process Coordination

Chapter 5: Process Synchronization

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

Background. The Critical-Section Problem Synchronisation Hardware Inefficient Spinning Semaphores Semaphore Examples Scheduling.

Process Synchronization: Semaphores. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

CS3733: Operating Systems

Chapter 6: Process Synchronization. Module 6: Process Synchronization

CS370 Operating Systems

Operating Systems. Operating Systems Summer 2017 Sina Meraji U of T

Synchronization Spinlocks - Semaphores

CS370 Operating Systems

Lesson 6: Process Synchronization

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

Concurrency. Chapter 5

Process Synchronization

The concept of concurrency is fundamental to all these areas.

Process Synchronization

Dept. of CSE, York Univ. 1

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition,

Chapter 7: Process Synchronization. Background

CHAPTER 6: PROCESS SYNCHRONIZATION

Chapter 6: Process Synchronization

IV. Process Synchronisation

Chapter 5 Concurrency: Mutual Exclusion. and. Synchronization. Operating Systems: Internals. and. Design Principles

Process Synchronization. CISC3595, Spring 2015 Dr. Zhang

Process Synchronization

Process/Thread Synchronization

Process Synchronization

Module 6: Process Synchronization. Operating System Concepts with Java 8 th Edition

COP 4225 Advanced Unix Programming. Synchronization. Chi Zhang

CS370 Operating Systems

Chapter 5: Process Synchronization

Interprocess Communication By: Kaushik Vaghani

CONCURRENCY:MUTUAL EXCLUSION AND SYNCHRONIZATION

Chapter 7: Process Synchronization. Background. Illustration

Concurrency: a crash course

Process Synchronization

Process Synchronization - I

Background. Old Producer Process Code. Improving the Bounded Buffer. Old Consumer Process Code

CSE 4/521 Introduction to Operating Systems

Concept of a process

Chapter 6 Synchronization

Chapter 6: Process Synchronization

Chapter 5: Process Synchronization

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }

IT 540 Operating Systems ECE519 Advanced Operating Systems

Module 6: Process Synchronization

CSC 1600: Chapter 6. Synchronizing Threads. Semaphores " Review: Multi-Threaded Processes"

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

Dealing with Issues for Interprocess Communication

Introduction to Operating Systems

Learning Outcomes. Concurrency and Synchronisation. Textbook. Concurrency Example. Inter- Thread and Process Communication. Sections & 2.

CS370 Operating Systems Midterm Review

Concurrency and Synchronisation

1. Motivation (Race Condition)

Concurrency: Mutual Exclusion and Synchronization

Process/Thread Synchronization

High-level Synchronization

Chapter 6: Process Synchronization. Operating System Concepts 9 th Edit9on

Synchronization. CSE 2431: Introduction to Operating Systems Reading: Chapter 5, [OSC] (except Section 5.10)

Comp 310 Computer Systems and Organization

Concurrency and Synchronisation

Principles of Operating Systems CS 446/646

Process Synchronisation (contd.) Deadlock. Operating Systems. Spring CS5212

Part II Process Management Chapter 6: Process Synchronization

Synchronization for Concurrent Tasks

Concurrency: Mutual Exclusion and Synchronization. Concurrency

Chapter 5 Concurrency: Mutual Exclusion and Synchronization

Chapter 6: Synchronization

More on Synchronization and Deadlock

Lecture Outline. CS 5523 Operating Systems: Concurrency and Synchronization. a = 0; b = 0; // Initial state Thread 1. Objectives.

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

CSE Traditional Operating Systems deal with typical system software designed to be:

Real-Time Operating Systems M. 5. Process Synchronization

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Process Co-ordination OPERATING SYSTEMS

Process Synchronization Mechanisms

Ch 9: Control flow. Sequencers. Jumps. Jumps

Process Synchronization

Chapter 6: Process Synchronization

Synchronization I. Jo, Heeseung

Transcription:

MS Windows Concurrency Mechanisms Prepared By SUFIAN MUSSQAA AL-MAJMAIE 163103058 April 2017

Basic of Concurrency In multiple processor system, it is possible not only to interleave processes/threads but to overlap them as well. Both techniques can be viewed as examples of concurrent processing and both present the same problems such as in sharing (global) resources e.g. global variables and in managing the allocation of resources optimally e.g. the request use of a particular I/O channel or device. The following figure try to describe the interleaving the processes. P stands for process and t is time. Figure 1: Interleave concept.

Figure 2: Process/thread Interleaving and overlapping

Core Core Thread 1 Thread 2 Thread 1 Thread 2 time Concurrency Management of concurrent activities in Windows operating System Multiple applications in progress at the same time, non-sequential operating system activities Time sharing for interleaved execution Demands dispatching and synchronization Parallelism: Actions are executed simultaneously Demands parallel hardware Core Relies on a concurrent application Memory Memory

Concurrency is Hard Sharing of global resources Concurrent reads and writes on the same variable makes order critical Optimal management of resource allocation Process gets control over a I/O channel and is then suspended before using it Programming errors become non-deterministic Order of interleaving may / may not activate the bug Happens all with concurrent execution, which means even on uniprocessors Race condition The final result of an operation depends on the order of execution Well-known issue since the 60 s, identified by E. Dijkstra

Race Condition void echo() { char_in = getchar(); char_out = char_in; putchar(char_out); } This is a critical section Executed by two threads on uniprocessor Executed by two threads on multiprocessor What happens?

Terminology Deadlock Two or more processes / threads are unable to proceed Each is waiting for one of the others to do something Livelock Two or more processes / threads continuously change their states in response to changes in the other processes / threads No global progress for the application Race condition Two or more processes / threads are executed concurrently Final result of the application depends on the relative timing of their execution

Potential Deadlock I need quad C and B I need quad B and C I need quad D and A I need quad A and B

Actual Deadlock HALT until D is free HALT until C is free HALT until A is free HALT until B is free

Terminology Starvation A runnable process / thread is overlooked indefinitely Although it is able to proceed, it is never chosen to run (dispatching / scheduling) Atomic Operation Function or action implemented as a sequence of one or more instructions Appears to be indivisible - no other process / thread can see an intermediate state or interrupt the operation Executed as a group, or not executed at all Mutual Exclusion The requirement that when one process / thread is using a resource, no other shall be allowed to do that

Critical Section n threads all competing to use a shared resource (i.e.; shared data, spaghetti forks) Each thread has some code - critical section - in which the shared data is accessed Mutual Exclusion demand Only one thread at a time is allowed into its critical section, among all threads that have critical sections for the same resource. Progress demand If no other thread is in the critical section, the decision for entering should not be postponed indefinitely. Only threads that wait for entering the critical section are allowed to participate in decisions. (deadlock problem) Bounded Waiting demand It must not be possible for a thread requiring access to a critical section to be delayed indefinitely by other threads entering the section. (starvation problem)

Critical Section Only 2 threads, T0 and T1 General structure of thread Ti (other thread Tj) Threads may share some common variables to synchronize their actions do { enter section critical section exit section reminder section } while (1);

Critical Section Protection with Hardware Traditional solution was interrupt disabling, but works only on multiprocessor Concurrent threads cannot overlap on one CPU Thread will run until performing a system call or interrupt happens Software-based algorithms also do not work, due to missing atomic statements Modern architectures need hardware support with atomic machine instructions Test and Set instruction - read & write memory at once If not available, atomic swap instruction is enough Busy waiting, starvation or deadlock are still possible #define LOCKED 1 int TestAndSet(int* lockptr) { int oldvalue; oldvalue = SwapAtomic(lockPtr, LOCKED); return oldvalue; } function Lock(int *lock) { while (TestAndSet (lock) == LOCKED); }

Manual implementation of a critical section for interleaved output 16

Binary and General Semaphores [Dijkstra] Find a solution to allow waiting processes to,sleep Special purpose integer called semaphore P-operation: Decrease value of its argument semaphore by 1 as atomic step Blocks if the semaphore is already zero - wait operation V-operation: Increase value of its argument semaphore by 1 as atomic step Releases one instance of the resource for other processes - signal operation wait (S): while (S <= 0); S--; // atomic signal (S): S++; // atomic do { wait(mutex); critical section signal(mutex); remainder section } while (1); Solution for critical section shared between N processes Binary semaphore has initial value of 1, counting semaphore of N

Semaphores and Busy Wait Semaphores may suspend/resume threads to avoid busy waiting On wait operation Decrease value When value <= 0, calling thread is suspended and added to waiting list Value may become negative with multiple waiters On signal operation Increase value When value <= 0, one waiting thread is woken up and remove from the waiting list typedef struct { int value; struct thread *L; } semaphore;

Shared Data Protection by Semaphores

References : - http://www.tenouk.com - https://computing.llnl.gov - Modern Operating, 3 rd ed., by Andrew Tanenbaum - Operating System ConcSystemsepts, 7 th ed., by Silbershatz, Galvin, & Gagne