DOC PREVIEW
UMD CMSC 412 - Operating Systems

This preview shows page 1-2-3-4-31-32-33-34-35-64-65-66-67 out of 67 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 67 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 67 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 67 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 67 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 67 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 67 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 67 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 67 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 67 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 67 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 67 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 67 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 67 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 67 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

16.1Silberschatz, Galvin and Gagne ©2005Operating System ConceptsCSMC 412CSMC 412Operating SystemsProf. Ashok K Agrawala© 2005 Ashok AgrawalaSet 66.2Silberschatz, Galvin and Gagne ©2005Operating System ConceptsProcess SynchronizationProcess Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Monitors Java Synchronization Solaris Synchronization Windows XP Synchronization Linux Synchronization Pthreads Synchronization Atomic Transactions Log-based Recovery Checkpoints Concurrent Transactions Serializability Locking Protocols26.3Silberschatz, Galvin and Gagne ©2005Operating System ConceptsConcurrency and SynchronizationConcurrency and Synchronization Concurrency The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors Synchronization in Solaris 2 & Windows 20006.4Silberschatz, Galvin and Gagne ©2005Operating System ConceptsSystems = Objects + ActivitiesSystems = Objects + Activities Safety is a property of objects, and groups of objects, that participate across multiple activities.z Can be a concern at many different levels: objects, composites, components, subsystems, hosts, … Liveness is a property of activities, and groups of activities, that span across multiple objects.z Levels: Messages, call chains, threads, sessions, scenarios, scripts workflows, use cases, transactions, data flows, mobile computations, …36.5Silberschatz, Galvin and Gagne ©2005Operating System ConceptsViolating SafetyViolating Safety Data can be shared by threadsz Scheduler can interleave or overlap threads arbitrarilyz Can lead to interferenceStorage corruption (e.g. a data race/race condition)Violation of representation invariantViolation of a protocol (e.g. A occurs before B)6.6Silberschatz, Galvin and Gagne ©2005Operating System ConceptsHow does this apply to How does this apply to OSsOSs?? Any resource that is shared could be accessed inappropriatelyz Shared memory Kernel threads Processes (shared memory set up by kernel)z Shared resources Printer, Video screen, Network card, … OS must protect shared resourcesz And provide processes a means to protect their own abstractions46.7Silberschatz, Galvin and Gagne ©2005Operating System ConceptsData Race ExampleData Race Examplestatic int cnt = 0;t1.run() {int y = cnt;cnt = y + 1;}t2.run() {int y = cnt;cnt = y + 1;}cnt = 0Start: both threads ready torun. Each will increment theglobal count. Shared state6.8Silberschatz, Galvin and Gagne ©2005Operating System ConceptsData Race ExampleData Race Examplestatic int cnt = 0;t1.run() {int y = cnt;cnt = y + 1;}t2.run() {int y = cnt;cnt = y + 1;}cnt = 0T1 executes, grabbingthe global counter value into y.Shared statey = 056.9Silberschatz, Galvin and Gagne ©2005Operating System ConceptsData Race ExampleData Race Examplestatic int cnt = 0;t1.run() {int y = cnt;cnt = y + 1;}t2.run() {int y = cnt;cnt = y + 1;}cnt = 0T1 is pre-empted. T2executes, grabbing the globalcounter value into y.Shared statey = 0y = 06.10Silberschatz, Galvin and Gagne ©2005Operating System ConceptsData Race ExampleData Race Examplestatic int cnt = 0;t1.run() {int y = cnt;cnt = y + 1;}t2.run() {int y = cnt;cnt = y + 1;}cnt = 1T2 executes, storing theincremented cnt value.Shared statey = 0y = 066.11Silberschatz, Galvin and Gagne ©2005Operating System ConceptsData Race ExampleData Race Examplestatic int cnt = 0;t1.run() {int y = cnt;cnt = y + 1;}t2.run() {int y = cnt;cnt = y + 1;}cnt = 1T2 completes. T1executes again, storing theold counter value (1) ratherthan the new one (2)!Shared statey = 0y = 06.12Silberschatz, Galvin and Gagne ©2005Operating System ConceptsBut When I Run it Again?But When I Run it Again?76.13Silberschatz, Galvin and Gagne ©2005Operating System ConceptsData Race ExampleData Race Examplestatic int cnt = 0;t1.run() {int y = cnt;cnt = y + 1;}t2.run() {int y = cnt;cnt = y + 1;}cnt = 0Start: both threads ready torun. Each will increment theglobal count. Shared state6.14Silberschatz, Galvin and Gagne ©2005Operating System ConceptsData Race ExampleData Race Examplestatic int cnt = 0;t1.run() {int y = cnt;cnt = y + 1;}t2.run() {int y = cnt;cnt = y + 1;}cnt = 0T1 executes, grabbingthe global counter value into y.Shared statey = 086.15Silberschatz, Galvin and Gagne ©2005Operating System ConceptsData Race ExampleData Race Examplestatic int cnt = 0;t1.run() {int y = cnt;cnt = y + 1;}t2.run() {int y = cnt;cnt = y + 1;}cnt = 1T1 executes again, storing thecounter valueShared statey = 06.16Silberschatz, Galvin and Gagne ©2005Operating System ConceptsData Race ExampleData Race Examplestatic int cnt = 0;t1.run() {int y = cnt;cnt = y + 1;}t2.run() {int y = cnt;cnt = y + 1;}cnt = 1T1 finishes. T2 executes, grabbing the globalcounter value into y.Shared statey = 0y = 196.17Silberschatz, Galvin and Gagne ©2005Operating System ConceptsData Race ExampleData Race Examplestatic int cnt = 0;t1.run() {int y = cnt;cnt = y + 1;}t2.run() {int y = cnt;cnt = y + 1;}cnt = 2T2 executes, storing theincremented cnt value.Shared statey = 0y = 16.18Silberschatz, Galvin and Gagne ©2005Operating System ConceptsWhat happened?What happened? In the first example, t1 was preempted after it read the counter but before it stored the new value.z Depends on the idea of an atomic actionz Violated an object invariant A particular way in which the execution of two threads is interleaved is called a schedule. We want to prevent this undesirable schedule. Undesirable schedules can be hard to reproduce, and so hard to debug.106.19Silberschatz, Galvin and Gagne ©2005Operating System ConceptsQuestionQuestion If you run a program with a race condition, will you always get an unexpected result?z No! It depends on the schedulerz ...and on the other threads/processes/etc that are running on the same CPU Race conditions are hard to find6.20Silberschatz, Galvin and Gagne ©2005Operating System ConceptsSynchronizationSynchronizationstatic int cnt = 0;struct Mutex lock;Mutex_Init(&lock);void run() {Mutex_Lock (&lock);int y = cnt;cnt = y + 1;Mutex_Unlock (&lock);}Lock, for protecting The shared stateAcquires the lock;Only succeeds if notheld by anotherthreadReleases the lock116.21Silberschatz, Galvin and Gagne ©2005Operating System ConceptsJavaJava--style style


View Full Document

UMD CMSC 412 - Operating Systems

Documents in this Course
Security

Security

65 pages

Deadlocks

Deadlocks

22 pages

Set 2

Set 2

70 pages

Project 2

Project 2

21 pages

Load more
Download Operating Systems
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Operating Systems and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Operating Systems 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?