assign2

Course: CS 571, Spring 2008
School: George Mason
Rating:
 
 
 
 
 

Word Count: 1047

Document Preview

MASON GEORGE UNIVERSITY Computer Science Department CS 571 Operating Systems Fall 2003 Assignment 2 Multithreaded Programming DUE DATE Oct 6 Process Synchronization The goal of this exercise to give you some experience writing concurrent programs. You have been hired by MetroTrans to synchronize trafc over a narrow light-duty bridge on a public highway. Trafc may only cross the bridge in one direction at a...

Register Now

Unformatted Document Excerpt

Coursehero >> Virginia >> George Mason >> CS 571

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
MASON GEORGE UNIVERSITY Computer Science Department CS 571 Operating Systems Fall 2003 Assignment 2 Multithreaded Programming DUE DATE Oct 6 Process Synchronization The goal of this exercise to give you some experience writing concurrent programs. You have been hired by MetroTrans to synchronize trafc over a narrow light-duty bridge on a public highway. Trafc may only cross the bridge in one direction at a time, and if there are ever more than 3 vehicles on the bridge at one time, it will collapse under their weight. In this system, each vehicle is represented by one thread, which executes the procedure OneVehicle when it arrives at the bridge: OneVehicle(int vehicle_id,int direc, int time_to_cross) { ArriveBridge(direc); CrossBridge(vehicle_id,direc,time_to_cross); ExitBridge(vehicle_id,direc); } In the code above, vehicle id is an integer which uniquely identies each vehicle (The vehicles arriving at the bridge should be assigned vehicle ids 1,2,3... and so on ). direc is either 0 or 1; it gives the direction in which the vehicle will cross the bridge. time to cross is the time it takes a vehicle to cross the bridge assume that every vehicle takes 4 seconds to cross the bridge. Implement a fair trafc control policy that imposes a limit (say 5) on the number of vehicles that can cross the bridge in one direction, while vehicles travelling in the opposite direction are waiting to get on the bridge. NOTE: if there are no vehicles waiting to get on the bridge in the opposite direction, your policy should not switch directions. In other words, your policy should be smart enough to provide fairness if there is trafc in both directions but should never force a vehicle to wait to get on the bridge if there is no trafc in the opposite direction. Write the procedures ArriveBridge,CrossBridge and ExitBridge, using mutex locks and condition variables for synchronization1 . The ArriveBridge procedure must not return until it is safe for the car to cross the bridge in the given direction (it must guarantee that there will be no head-on collisions or bridge collapses). The CrossBridge procedure should just delay for time to cross seconds and print out a debug message. ExitBridge is called to indicate that the caller has nished crossing the bridge; ExitBridge should take steps to let additional cars cross the bridge. In addition, ExitBridge should update a shared variable departure index, which keeps track of the order in which the cars leave the bridge, i.e., the rst car to leave the bridge has departure index 1, the second car has departure index 2, and so on. The ExitBridge procedure should also print out the departure index for that vehicle. 1 If you use Java for the assignment, use the equivalent thread synchronization faciltities 1 NOTES: Your solution must not employ busy waiting. Your solution must use two queues on either end of the bridge where vehicles wait until it is safe for them to enter the bridge. In terms of threads, this means that you need two condition variables (or Java objects) where a thread is suspended if it cannot enter the CrossBridge procedure. For full credit, your solution must not use the pthread cond broadcast() (or function if youre using Java, the notify all() method), i.e. your solution must only use pthread cond signal() or notify() for signalling any threads blocked on a condition variable. NOTE: invoking pthread cond signal() or notify() repeatedly in a loop is equivalent to pthread cond broadcast() and notify all() Occasionally, a vehicle (thread) may overtake another vehicle travelling in the same direction on the bridge. Do not worrry about this. You do not have to ensure that vehicles leave the bridge in the same order as they entered it. The debug message printed out in CrossBridge should provide a snapshot of the bridge and the queues on the two ends of the bridge. It is probably also a good idea to print out debug messages in ArriveBridge and ExitBridge. In this assignment, you have to run your program for the three vehicle arrival schedules given below: (i) 5 : DELAY(10) : 5 : DELAY(10) : 5 : DELAY(10) : 5: DELAY(10) : 5 : DELAY(10) : 5 (ii) 10 : DELAY(10) : 10 : DELAY(10): 10 (iii) 30 Here the numbers indicate the number of vehicles arriving simultaneously at the bridge, while the numbers in parentheses indicate the delay before the next arrival(s). For example, under schedule (i) 5 vehicles arrive simultaneously at the bridge at the start of the experiment, ve more vehicles arrive simultaneously 10 seconds after the arrival of the rst ve vehicles and so on. In each of the three schedules, thirty vehicles arrive at the bridge during the course of the experiment. Note that vehicles arriving simultaneously does not imply that they are all traveling in the same direction. Assume that the probability that a vehicle is traveling in direction 0 is 0.6 NOTES: 1. You can use either Java or the Pthreads multithreaded programming library for doing this assignment. Both Java and the Pthreads library are available on machines in the IT&E lab. 2. On Solaris, information on ho...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

George Mason - CS - 367
Chapter 4 The Von Neumann ModelACKNOWLEDGEMENT: This lecture uses slides prepared by Gregory T. Byrd, North Carolina State University4-21The Stored Program Computer1943: ENIAC Presper Eckert and John Mauchly - first general electronic compu
George Mason - CS - 367
Bitwise OperatorsSymbol ~ < > & ^ | Operation bitwise NOT left shift right shift bitwise AND bitwise XOR bitwise OR Usage ~x x < y x > y x & y x ^ y x | yPrecedence 4 8 8 11 12 13 Assoc r-to-l l-to-r l-to-r l-to-r l-to-r l-to-rOperate on variable
George Mason - CS - 365
Ch 5: Designing a Single Cycle DatapathComputer Systems Architecture CS 365The Big Picture: Where are We Now? The Five Classic Components of a ComputerProcessor Input Control Memory Datapath Output Today Topic: Design a Single Cycle Processo
George Mason - CS - 818
Privacy and Security in library RFID Issues, Practices and ArchitectureDavid Molnar and David Wagner University of California, BerkeleyCCS '04 October 2004OverviewMotivation RFID Background Library RFID IssuesCurrent Architectures, Atta
George Mason - CS - 580
T R E N D S&C O N T R O V E R S I E SPlaying with AIThe use of puzzles and games in AI research dates to its earliest days. In the early 1950s, Claude Shannon and Alan Turing wrote papers proposing the creation of computer programs that could
George Mason - CS - 803
Data-Hiding CodesPIERRE MOULIN, FELLOW, IEEE, AND RALF KOETTER, MEMBER, IEEE Invited PaperThis tutorial paper reviews the theory and design of codes for hiding or embedding information in signals such as images, video, audio, graphics, and text. S
George Mason - CS - 682
CS 682: Computer VisionDr. Zoran DuricCS Dept. GMUJanuary 27, 2009Oce: S&T II, Rm. 427 email: zduric@cs.gmu.edu Oce Hours: Tue. 2:00-4:00pm, Thu 1:30-2:30pm or by app. URL: http:/www.cs.gmu.edu/zduric/ Course: http:/www.cs.gmu.edu/zduric/cs682.
George Mason - CS - 580
CS 580'$1Introduction to Articial Intelligence: cs580Dr. Zoran Duric Oce: S&T II, Rm. 427 email: zduric@cs.gmu.edu Oce Hours: Tue. 2:00-4:00pm or by app. URL: http:/www.cs.gmu.edu/zduric/ Course: http:/www.cs.gmu.edu/zduric/cs580.html&%
George Mason - CS - 580
LispLisp: Question 1Write a recursive lisp function that takes a list as an argument and returns the number of atoms on any level of the list. For instance, list (A B (C D E ) () contains six atoms (A, B, C , D, E , and NIL). (defun count-atoms (
George Mason - CS - 580
'$Intelligent AgentsChapter 2&1%'$Outline Agents and environments Rationality PEAS (Performance measure, Environment, Actuators, Sensors) Environment types Agent types&2%'$Agents and environmentssensors percepts envi
George Mason - CS - 580
X X X X X1/ 10 Dr. Zoran Duric (CS Dept., GMU)MAX nodes MIN nodesXStart nodeAlpha-Beta Pruning ExampleAlpha-Beta Pruning(Backed-up value = +1)XX X X 1998 Morgan Kaufman PublishersMidterm Review 3XX X2 +2 3 +3 1 1 +1 +5 +4 +1
George Mason - CS - 682
Projectss s sSummarizing videossSummarizing videos Find image copies Detecting motion patterns in surveillance videoss sUse edge and flow histograms as image descriptors to summarize videos Use k-means to find sub-sequence center frames Tes
George Mason - CS - 112
Pickling and ShelvesDan FleckComing up: What is pickling?What is pickling?Pickling - is the process of preserving food by anaerobic fermentation in brine (a solution of salt in water), to produce lactic acid, or marinating and storing it in an
George Mason - CS - 112
CS 112 Lab AssignmentInstructor: Dan Fleck Lab: 401K MathOverviewThis lab will help you understand the mathematical operators in Python and how to get user input. Additionally, it will show you the financial benefits of a 401(k) program, and why
George Mason - CS - 112
CS 112 Lab AssignmentInstructor: Dan Fleck Lab: Web Favorites (to learn how to create and use Classes) Due Date: As with all labs, this lab is due one week from your lab section!OverviewThis lab will familiarize you with creating and using Classe
George Mason - CS - 112
Python Programming: An Introduction To Computer ScienceChapter 8 BooleansComing up: Computing with Booleans1Computing with Booleans!if and while both use Boolean expressions. ! Boolean expressions evaluate to True or False. ! So far weve used
George Mason - CS - 112
Python Programming: An Introduction to Computer ScienceChapter 4 (End of Chapter) File IOComing up: File Processing1File Processing! The process of opening a file involves associating a file on disk with a variable. ! We can manipulate the fi
George Mason - CS - 112
Creating a large GUI ProgramDan Fleck Spring 2007Coming up: Hangman yes again!Hangman yes again!! Lets say we want to create a more fun, graphical version of our Hangman game. This is alarger program and we will follow the Software Developmen
George Mason - CS - 112
The Software Development Process Python Programming: An Introduction to Computer Science Chapter 2 Dan Fleck The process of creating a program is often broken down into stages according to the information that is produced in each phase.Coming up:
George Mason - CS - 112
Passing a function as a parameter and How NOT to do menusDan FleckComing up: Passing Functions as ParametersPassing Functions as Parameters You have seen in GUI programming that Buttons (for example) allow you to pass a function to the button t
George Mason - CS - 112
Objectives Python Programming: An Introduction to Computer ScienceChapter 3 Computing with Numbers Updated by Dan FleckComing up: Objectives 1 Coming up: Numeric Data Types 2 To understand the concept of data types. To be familiar with the basic
George Mason - CS - 112
The Function of Functions Python Programming: An Introduction to Computer ScienceChapter 6 Functions,Variables,Modules Why use functions at all? Reduces duplicate code (Less maintenance, debugging, etc) Makes programs easier to read Makes progra
George Mason - CS - 112
The String Data Type Python Programming: An Introduction to Computer ScienceChapter 4 Computing with Strings The most common use of personal computers is word processing. Text is represented in programs by the string data type. A string is a sequ
George Mason - CS - 112
Debugging & Errors Why you were up till 2AMDan Fleck Fall 2008Coming up: Running programs from the command lineRunning programs from the command lineIn windows just double-click on the sliders.py le In Unix/Mac (or Windows also) run the command
George Mason - CS - 112
Sorting and ComparatorsDan FleckComing up: Sorting a listSorting a list! Sorting a list seems simple: myList = [1, 4, 3, 5] myList.sort() print myList > [1, 3, 4, 5] Backwards? Not so hard reallyOkay, how about backwards then!! A little hard
George Mason - CS - 112
Exception HandlingDan FleckComing up: Long ago we wrote thisLong ago we wrote thisdef addGraphicalButton(parent): # Create the PhotoImage widget im = PhotoImage(file='cake.gif') button2 = Button(root, text="Potato", image=im) button2.image = im
George Mason - CS - 112
Python Programming: An Introduction To Computer ScienceChapter 10 Defining Classes (These slides were heavily editted/ rewritten by Dan Fleck)Coming up: Objectives 1Objectives! To appreciate how defining new classes can provide structure for a c
George Mason - CS - 112
Python Programming: An Introduction to Computer ScienceChapter 1 Computers and Programs Modified by Dan FleckObjectives Introduction to the class Why we program and what that means Introduction to the Python programming languageComing up: Wha
George Mason - CS - 112
Tkinter GUIs in PythonDan Fleck CS112 George Mason UniversityNOTE: This information is not in your textbook! See references for more information!Coming up: What is it?What is it?! Tkinter is a Python interface to the Tk graphics library.!Tk i
George Mason - CS - 112
New Datatypes:Tuples and SetsDan FleckComing up: Passing a list as a parameterPassing a list as a parameterdef class FamilyTree:# This class holds a list of family members in the variable tree lots of code not shown def getTree(self): retur
George Mason - CS - 112
CS 112 Lab AssignmentInstructor: Dan Fleck Lab: Pig Latin TranslatorOverviewThis lab will familiarize you with the String class and String functions available in Python. You will be ask the user for a word and convert it into PigLatin. Pig Latin
George Mason - CS - 112
CS 112 Lab AssignmentInstructor: Dan Fleck Lab: Graphics Due Date: SPECIAL ALERT: This lab (and ONLY this lab) will be due on April 14th at midnight for EVERYONE. Just this once well have a longer due date for people because of the midterm the week
George Mason - CS - 112
CS 112 Lab AssignmentInstructor: Dan Fleck Lab: Software design and documentation Due Date: As with all labs, this lab is due one week from your lab section!OverviewThroughout the semester you have hopefully been writing pseudocode and adding goo
George Mason - CS - 112
CS 112 Lab AssignmentInstructor: Dan Fleck Lab: #1OverviewThis lab will help you familiarize yourself with Python, the computer lab and Blackboard. For this lab you will do two things: 1. Type in and run a simple Python file 2. Submit that file a
George Mason - CS - 112
CS 112 Lab AssignmentInstructor: Dan Fleck Lab: For Loops (and a little math)OverviewThis lab will help you understand how to use for loops. You will compute an estimated value for the square root of a number to a specific accuracy given from the
George Mason - CS - 112
CS 112 Project Assignment: SlidersInstructor: Dan FleckOverviewIn this project you will use Python to implement the number sliders game. This game can be seen at: http:/www.classbrain.com/artgames/publish/sliders_game.shtml You will only be imple
George Mason - CS - 540
Building SLR Parse TablesThe easiest technique for generating LR-based parse table is known as SLR (Simple LR). Understanding this technique should provide you with what you need to know to understand how LR parsers work in general; it is also the f
George Mason - CS - 367
Introduction to CAcknowledgement: These slides are adapted from lecture slides made available by Prof. Dave O Halloran (Carnegie Mellon University)Outline Overview comparison of C and Java Good evening Preprocessor Command line arguments Arr
George Mason - CS - 707
Assignment #2 - Auction ToolDue April 12IntroductionThe goal of this assignment is to introduce you to the use of a distributed object middleware such as CORBA or Java RMI to build a distributed auction tool. This tool will allow users to create
George Mason - CS - 640
SPECIALISSUEArticlesADVANCED COMPILER OPTIMIZATIONS FOR SUPERCOMPUTERSCompilers for vector or multiprocessor computers must have certain optimization features to successfully generate parallel code.DAVID A. PADUA and MICHAEL J. WOLFESuperco
George Mason - CS - 640
REGISTER ALLOCATION & SPILLING VIA GRAPH COLORING G. J. Chaitin IBM Research P.O.Box 218, Yorktown Heights, NY 10598ABSTRACT In a previous paper we reported the successful use of graph coloring techniques for doing global register allocation in an
George Mason - CS - 367
Programming in C in a UNIX environmentSoftware Development LifecycleUnderstand the requirements Develop the algorithm/approach Write the code Debug the code Test the code Iterate until you get it right2Programming ToolsSeveral Integrated Deve
George Mason - CS - 640
Improvements to Graph Coloring Register AllocationPRESTON BRIGGS, KEITH D. COOPER, and LINDA TORCZON Rice UniversityWe describeopttmzstwtwo improvements to Chaitin-style graph coloring register allocators. The first, uses a stronger heuristic t
George Mason - CS - 640
CS 640 HW #1 Fall 2008 Due Sept 22 at classtime1. For the code below, what optimizations can be detected using Local Value Numbering? What about DAG construction? a = 2 b = 3 c = a + b d = a + a b = a e = a + b c = 3 f = a + c 2. In order to do supe
George Mason - CS - 640
Redundant Expression EliminationCS640 Lecture 3Redundant ExpressionstDefinitionrAn expression x op y is redundant at a point p if it has already been computed and no intervening operations redefined x or y Preserve the result of earlier comp
George Mason - CS - 640
CS640Advanced CompilersInstructor: Elizabeth Whitewhite@gmu.eduAbout the CourseInstructor: Dr. Elizabeth WhiteEmail: white@gmu.edu Office: STII 429 Office hour:Mon/Wed 2-3 By appointmentCourse web site:http:/cs.gmu.edu/~white/CS640 Check
George Mason - CS - 707
ProcessesCh. 1, 3 Tanenbaum Distributed Software Systems CS 707Software ArchitectureComponents/processesprocess = program in execution Often multi-threaded! How the processes are organized influences the overall applicationConnections between
George Mason - CS - 571
Java Thread ProgrammingThreads are built in to Java and work the same way on all platforms. Underlying implementation can vary from one platform to the next but you don't need to worry about it.GMU CS 571 - Java Thread Programming - Brian Zim
George Mason - CS - 640
Interprocedural Analysis & OptimizationCS640 Lecture 12RoadmapA compiler need to perform all kinds of analysis before code transformation Controlflow analysisBasic blocks, loops, CFG (one for each procedure) Data flow analysisLocal
George Mason - CS - 707
Local Objects vs. Distributed ObjectsLocal objects are those whose methods can only be invoked by a local process, a process that runs on the same computer on which the object exists. A distributed object is one whose methods can be invoked by a rem
George Mason - CS - 707
TonightSeveral common communication mechanisms RPC RMI Sockets Next week: HTTP, CommunicationTanenbaum Ch. 4 Distributed Software Systems CS 707Middleware ProtocolsRemote Procedure Call (RPC)Figure 4-3. An adapted reference model for ne
George Mason - CS - 707
Traditional Web-Based Systems - 1Chapter 12 Distributed Web-Based SystemsFigure 12-1. The overall organization of a traditional Web site.Traditional Web-Based Systems - 2Terminology URI Uniform Resource Identifier (URL, URN) Web client (bro
George Mason - CS - 640
CS 640 HW #2 Fall 2008 Due Oct 6 at classtime1. Dataflow analysis can be used to propagate constants in a CFG. Give a dataflow algorithm for this be sure to provide details regarding the transfer functions (and how they are computed). Show how your
George Mason - CS - 640
Static Single AssignmentCS 640 Lecture 5VN Example ReviewOriginal Code ax+y bx+y a 17 cx+y With VNs a3 x1 + y2 b3 x1 + y2 a4 174 c3 x1 + y2 Rewritten a03 x01 + y02 b03 a03 a14 174 c03 a03Give each value a unique name No value is
George Mason - CS - 540
Lecture 7: Type Systems and Symbol TablesCS 540 George Mason UniversityStatic AnalysisCompilers examine code to find semantic problems. Easy: undeclared variables, tag matching Difficult: preventing execution errors Part I: Type checking Par
George Mason - CS - 540
Lecture 3: ParsingCS 540 George Mason UniversityStatic Analysis - ParsingSource languageScanner (lexical analysis)tokensParser (syntax analysis)Syntatic structureSyntatic/semantic structureSemantic Analysis (IC generator)Code Genera
George Mason - CS - 540
Lecture 5: LR ParsingCS 540 George Mason UniversityStatic Analysis - ParsingSource languageScanner (lexical analysis)tokensParser (syntax analysis)Syntatic structureSyntatic/semantic structureSemantic Analysis (IC generator)Code Gen
George Mason - CS - 540
Lecture 6: YACC and Syntax Directed TranslationCS 540 George Mason UniversityPart 1: Introduction to YACCYACC Yet Another Compiler CompilerLex spec flex lex.yy.c compiler YACC spec bison y.tab.c a.outC/C+ toolsCS 540 Spring 2009 GMU 3YACC
George Mason - CS - 540
Lecture 2: Lexical AnalysisCS 540 George Mason UniversityLexical Analysis - ScanningSource language Scanner (lexical analysis) tokens Parser (syntax analysis) Semantic Analysis (IC generator) Code GeneratorCode Optimizer Tokens described form
George Mason - CS - 540
Lecture 8: Intermediate CodeCS 540 Spring 2009Compiler ArchitectureSource languageScanner (lexical analysis)tokensParser (syntax analysis)Syntactic structureIntermediate CodeSemantic Analysis (IC generator)Code GeneratorTarget lan
George Mason - CS - 540
Lecture 4: LL ParsingCS 540 George Mason UniversityParsingSource languageScanner (lexical analysis)tokensParser (syntax analysis)Syntatic structureSyntatic/semantic structureSemantic Analysis (IC generator)Code GeneratorTarget lan