Semaphore and Multithreading

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Operating Systems Part III: Process Management (Process Synchronization)
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
© 2013 IBM Corporation Enabling easy creation of HW reconfiguration scenarios for system level pre-silicon simulation Erez Bilgory Alex Goryachev Ronny.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 6: Process Synchronization
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
EEE 435 Principles of Operating Systems Interprocess Communication Pt II (Modern Operating Systems 2.3)
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.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
CS533 - Concepts of Operating Systems
1 Chapter 6: Concurrency: Mutual Exclusion and Synchronization Operating System Spring 2007 Chapter 6 of textbook.
1 MATERI PENDUKUNG SINKRONISASI Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Input / Output CS 537 – Introduction to Operating Systems.
1 Advanced Computer Programming Concurrency Multithreaded Programs Copyright © Texas Education Agency, 2013.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Understanding Operating Systems Fifth Edition Chapter 6 Concurrent Processes.
Understanding Operating Systems 1 Chapter 6 : Concurrent Processes What is Parallel Processing? Typical Multiprocessing Configurations Process Synchronization.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
Games Development 2 Concurrent Programming CO3301 Week 9.
Operating Systems CSE 411 Multi-processor Operating Systems Multi-processor Operating Systems Dec Lecture 30 Instructor: Bhuvan Urgaonkar.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
2.3 interprocess communcation (IPC) (especially via shared memory & controlling access to it)
Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution.
DSP/BIOS for C6000/C5000. What is DSP/BIOS Real-time Environment –Thread execution model Threads, Mailboxes, Semaphores –Device independent I/O Logging,
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Operating System Concepts and Techniques Lecture 13 Interprocess communication-2 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and.
SMP Basics KeyStone Training Multicore Applications Literature Number: SPRPxxx 1.
Process Synchronization. Concurrency Definition: Two or more processes execute concurrently when they execute different activities on different devices.
Pitfalls: Time Dependent Behaviors CS433 Spring 2001 Laxmikant Kale.
Computer Organization
SLC/VER1.0/OS CONCEPTS/OCT'99
Process Management Process Concept Why only the global variables?
Background on the need for Synchronization
Lesson Objectives Aims Key Words Interrupt, Buffer, Priority, Stack
Operating Systems (CS 340 D)
G.Anuradha Reference: William Stallings
CSC 4250 Computer Architectures
Computer Architecture
Chapter 6 Concurrent Processes
Chapter 5: Process Synchronization
Operating Systems (CS 340 D)
Concurrency: Mutual Exclusion and Synchronization
Serial Communication Interface: Using 8251
Computer System Overview
Processor Fundamentals
Shared Memory Programming
Thread Synchronization
Critical section problem
Threads Chapter 4.
Grades.
Concurrency: Mutual Exclusion and Process Synchronization
Chapter 6: Process Synchronization
Concurrency and Immutability
- When you approach operating system concepts there might be several confusing terms that may look similar but in fact refer to different concepts:  multiprogramming, multiprocessing, multitasking,
Chapter 6: Synchronization Tools
Chapter 2 Operating System Overview
Process Management -Compiled for CSIT
Operating System Overview
Lecture 18: Coherence and Synchronization
CS 144 Advanced C++ Programming May 7 Class Meeting
Jazan University, Jazan KSA
Ch 3.
Chapter 3: Process Management
Presentation transcript:

Semaphore and Multithreading -Sagar Panchariya

Semaphore A hardware or software flag. A Semaphore is a variable with a value that indicates the status of a common resource. It's used to lock the resource that is being used. A process needing the resource checks the semaphore to determine the resource's status and then decides how to proceed

Resource Semaphore Load data(signal); Wait(signal); Process(data);) Buffer I/O Device Start processing Load data

Multithreading The ability to execute different parts of a program, called threads, simultaneously. Different parts of a program may be: I/O operations Data Processing Advantages:- Multithreading, when done correctly, offers better utilization of processors and other system resources.

Multithreading Problems to be taken care of: Race conditions: Two or more threads try and update the same resource <variable> without proper synchronization. Solution: Use of semaphores, to bring in synchronization among threads.

C” Programming example Mono Memory Mono Memory Input Data 0 1 2 3 96 192 Read Sem async_memcpym2p Read Sem async_memcpyp2m Output Data 0 2 4 6 384 Write Sem SRC_addr DST_addr 96 PE Array Memory Background buffer Elements[0] Active buffer Elements[1]

1. Read into the active buffer. 2. Wait for the background buffer to be empty then read the next chunk into it. 3. Wait for the active buffer to be full then process the contents. 4. Write out the active buffer. 5. Swap the active and background buffers. 6. Repeat from 2 until all chunks are processed. 7. Wait for the write of the last active buffer to finish then print the results to the console.

Two semaphores are used: one to synchronize reading a buffer and processing that data; the second to synchronize writing the data with refilling the buffer Code snapshot:-- async_memcpym2p(READ_SEMAPHORE_a, &element[active], src_addr, sizeof(float)); sem_wait(READ_SEMAPHORE_a); //do the processing on all data in parallel element[active] *= scale; async_memcpyp2m(WRITE_SEMAPHORE, dst_addr, &element[active], sizeof(float));

Semaphore debug commands sem help To give description of all semaphore commands sem display all Displays all semaphore sem display allval Display all semaphores with value Sem display <semaphore no>

Thanks