LSU CSC 4101 - Programming Languages (16 pages)

Previewing pages 1, 2, 3, 4, 5 of 16 page document View the full content.
View Full Document

Programming Languages



Previewing pages 1, 2, 3, 4, 5 of actual document.

View the full content.
View Full Document
View Full Document

Programming Languages

83 views


Pages:
16
School:
Louisiana State University
Course:
Csc 4101 - Prog Languages

Unformatted text preview:

Programming Languages Tevfik Ko ar Lecture XXVII May 2nd 2006 1 Roadmap Shared Memory Cigarette Smokers Problem Monitors Message Passing Cooperative Operations Synchronous and Asynchronous Sends Blocking and Non blocking Operations Collective Communications 2 1 Cigarette Smokers Problem Assume a cigarette requires three ingredients to smoke Tobacco Paper Match Assume there are also three smokers around a table each of whom has an infinite supply of one of the three ingredients Assume there is also a non smoking arbiter The arbiter enables the smokers to make their cigarettes by selecting two of the smokers at random taking one item out of each of their supplies and placing the items on the table He then notifies the third smoker that he has done this The third smoker removes the two items from the table and uses them along with his own supply to make a cigarette which he smokes for a while Meanwhile the arbiter seeing the table empty again chooses two smokers at random and places their items on the table This process continues forever 3 Solution Let us define an array of binary semaphores A one for each smoker and a binary semaphore for the table T Initialize the smokers semaphores to zero and the table s semaphore to 1 Then the arbiter s code is while true wait T choose smokers i and j randomly making the third smoker k signal A k 4 2 Solution cont And the code for smoker i is while true wait A i make a cigarette signal T smoke the cigarette 5 Semaphores Although widely used they are considered as too low level and generally used low level code eg operating systems Since their operations are simply subroutine calls it is very easy to leave out one eg forgetting to release a semaphore that has been taken Generally scattered throughout a program and hard to debug and maintain 6 3 Monitors Suggested by Dijkstra 72 Formulized by Hoare 74 Monitors encapsulate all synchronization code into a single structure like objects in OOP Only one operation of a given monitor is



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Programming Languages 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 Programming Languages 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?