DOC PREVIEW
UB CSE 421 - Posix Library Implementation

This preview shows page 1-2-3-22-23-24-44-45-46 out of 46 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 46 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 46 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 46 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 46 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 46 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 46 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 46 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 46 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 46 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 46 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Posix Library Implementation Based F. Mueller’s PaperPthread_join and Pthread_detach functionInter-Process Communication and SynchronizationIntroductionTopics for discussionPrinciples of Concurrency...Concurrency (contd.)Interactions among processesInteractions ...(contd.)Race ConditionMutual exclusion problemMutual exclusionSoftware Solutions: Algorithm 1Algorithm 2Algorithm 3Synchronization HardwareMutual Exclusion with Test-and-SetSynchronization HardwareMutual Exclusion with SwapSemaphoresCritical Section of n ProcessesSemaphore ImplementationSemantics of wait and signalSemaphores for CSTwo Types of SemaphoresSemaphore for SynchronizationClassical Problems of SynchronizationProducer/Consumer problemSolution for P/C using SemaphoresP/C: improved solutionP/C problem: Bounded bufferP/C: Bounded Buffer solutionSemaphores - commentsMonitorsSlide 35Slide 36Schematic View of a MonitorMonitor With Condition VariablesMessage passingIssues in message passingReader/Writer problemReader/writer: Priority ReadersDining Philosophers ExampleDining PhilosophersSlide 45SummaryPosix Library ImplementationBased F. Mueller’s PaperLanguage ApplicationLanguage Interface C Language ApplicationPosix thread libraryUnix KernelUnix librariesUser LevelKernel LevelPthread_join and Pthread_detach function•Pthread_join(tid, ..) : executing threads blocks waiting for the thread tid to exit.•Pthread_detach(tid,..): request reclaiming of the resources of the thread tid, if it has completed. ( This is more to take some implementation variations).Inter-Process Communication and SynchronizationB. RamamurthyIntroduction•An important and fundamental feature in modern operating systems is concurrent execution of processes/threads. This feature is essential for the realization of multiprogramming, multiprocessing, distributed systems, and client-server model of computation.•Concurrency encompasses many design issues including communication and synchronization among processes, sharing of and contention for resources.•In this discussion we will look at the various design issues/problems and the wide variety of solutions available.Topics for discussion•The principles of concurrency•Interactions among processes•Mutual exclusion problem•Mutual exclusion- solutions–Software approaches (Dekker’s and Peterson’s)–Hardware support (test and set atomic operation)–OS solution (semaphores)–PL solution (monitors)–Distributed OS solution ( message passing)•Reader/writer problem•Dining Philosophers ProblemPrinciples of Concurrency•Interleaving and overlapping the execution of processes.•Consider two processes P1 and P2 executing the function echo:{ input (in, keyboard); out = in; output (out, display);}...Concurrency (contd.)•P1 invokes echo, after it inputs into in , gets interrupted (switched). P2 invokes echo, inputs into in and completes the execution and exits. When P1 returns in is overwritten and gone. Result: first ch is lost and second ch is written twice.•This type of situation is even more probable in multiprocessing systems where real concurrency is realizable thru’ multiple processes executing on multiple processors.•Solution: Controlled access to shared resource–Protect the shared resource : in buffer; “critical resource”–one process/shared code. “critical region”Interactions among processes•In a multi-process application these are the various degrees of interaction:1. Competing processes: Processes themselves do not share anything. But OS has to share the system resources among these processes “competing” for system resources such as disk, file or printer. Co-operating processes : Results of one or more processes may be needed for another process. 2. Co-operation by sharing : Example: Sharing of an IO buffer. Concept of critical section. (indirect)3. Co-operation by communication : Example: typically no data sharing, but co-ordination thru’ synchronization becomes essential in certain applications. (direct)Interactions ...(contd.)•Among the three kinds of interactions indicated by 1, 2 and 3 above:•1 is at the system level: potential problems : deadlock and starvation.•2 is at the process level : significant problem is in realizing mutual exclusion.•3 is more a synchronization problem.•We will study mutual exclusion and synchronization here, and defer deadlock, and starvation for a later time.Race Condition•Race condition: The situation where several processes access – and manipulate shared data concurrently. The final value of the shared data depends upon which process finishes last.•To prevent race conditions, concurrent processes must be synchronized.Mutual exclusion problem•Successful use of concurrency among processes requires the ability to define critical sections and enforce mutual exclusion.•Critical section : is that part of the process code that affects the shared resource.•Mutual exclusion: in the use of a shared resource is provided by making its access mutually exclusive among the processes that share the resource.•This is also known as the Critical Section (CS) problem.Mutual exclusion•Any facility that provides mutual exclusion should meet these requirements: 1. No assumption regarding the relative speeds of the processes.2. A process is in its CS for a finite time only.3. Only one process allowed in the CS.4. Process requesting access to CS should not wait indefinitely.5. A process waiting to enter CS cannot be blocking a process in CS or any other processes.Software Solutions: Algorithm 1•Process 0•...•while turn != 0 do• nothing;•// busy waiting•< Critical Section>•turn = 1;•...Problems : Strict alternation, Busy Waiting•Process 1•...•while turn != 1 do• nothing;•// busy waiting•< Critical Section>•turn = 0;•...Algorithm 2•PROCESS 0•...•flag[0] = TRUE;•while flag[1] do nothing;•<CRITICAL SECTION>•flag[0] = FALSE;PROBLEM : Potential for deadlock, if one of the processes fail within CS.•PROCESS 1•...•flag[1] = TRUE;•while flag[0] do nothing;•<CRITICAL SECTION>•flag[1] = FALSE;Algorithm 3•Combined shared variables of algorithms 1 and 2.•Process Pido {flag [i]:= true;turn = j;while (flag [j] and turn = j) ;critical sectionflag [i] = false;remainder section} while (1);•Solves the critical-section problem for two processes.Synchronization Hardware•Test and modify the content of a word atomically.boolean TestAndSet(boolean &target)


View Full Document

UB CSE 421 - Posix Library Implementation

Documents in this Course
Security

Security

28 pages

Threads

Threads

24 pages

Security

Security

20 pages

Security

Security

52 pages

Security

Security

20 pages

Load more
Download Posix Library Implementation
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 Posix Library Implementation 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 Posix Library Implementation 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?