Starting from:
$30

$24

CS 343 Assignment 5 Solved

This assignment introduces monitors and task communication in µC++. Use it to become familiar with these new facilities, and ensure you use these concepts in your assignment solution.




Watch the video clip http://www.youtube.com/watch?v=ByPrDPbdRhc from the Dr. Who episode “Blink”. Warn-ing: it is scary but not violent. At the climax, is there a livelock or deadlock among the Angels? Explain the livelock/deadlock in detail. (You have to be generous as to what the Angels can see.)



(a) Consider the following situation involving a tour group of V tourists. The tourists arrive at the Louvre museum for a tour. However, a tour group can only be composed of G people at a time, otherwise the tourists cannot hear the guide. As well, there are 3 kinds of tours available at the Louvre: pictures, statues and gift shop. Therefore, each tour group must vote to select the kind of tour to take. Voting is a ranked ballot, where each tourist ranks the 3 tours with values 0, 1, 2, where 2 is the highest rank. Tallying the votes sums the ranks for each kind of tour and selects the highest ranking. If tie votes occur among rankings, prioritize the results by gift shop, pictures, and then statues, e.g.:



   

P
S G
tourist1
0
1
2
tourist2
2
1
0
tally
2
2 2 all ties, select G



During voting, a tourist blocks until all votes are cast, i.e., assume a secret ballot. Once a decision is made, the tourists in that group proceed on the specified tour. Tourists may take multiple tours, but because of voting, end up taking the same kind of tour.




The tour size G may not evenly divide the number of tourists, resulting in a quorum failure when the remaining tourists is less than G. Note, even when V is a multiple of G and tourists take multiple tours, a quorum failure can occur. For example, one tour is faster than another or a tourist leaves a tour early and comes back to vote on another tour, so the quick tourist finishes all their tours and terminates. The slower tourists then encounter a situation where there are insufficient tourists to form a quorum for later tours.




Implement a general vote-tallier for G-way voting as a:




µC++ monitor using external scheduling,



µC++ monitor using internal scheduling,



µC++ monitor using only internal scheduling but simulates a Java monitor,



In a Java monitor, there is only one condition variable and calling tasks can barge into the monitor ahead of signalled tasks. Figure 1 shows a µC++ simulation of Java barging by replacing the normal calls to condition-variable wait and signal with these calls. This code randomly accepts calls to the interface routines, if a caller exists. Only condition variable bench may be used and it may only be accessed via member routines wait() and signalAll(). Hint: to control barging tasks, use a ticket counter.




µC++ monitor that simulates a general automatic-signal monitor,



µC++ does not provide an automatic-signal monitor so it must be simulated using the explicit-signal mechanisms. For the simulation, create an include file, called AutomaticSignal.h, which defines the following preprocessor macros:




#define AUTOMATIC_SIGNAL . . .

#define WAITUNTIL( pred, before, after ) . . .

#define EXIT() . . .

  
 
 
 
 CS 343 - Assignment 5
6



    
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
      
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
     
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lines in




 CS 343 - Assignment 5
7









Compare the performance among the 5 kinds of monitors/task by eliding all output (not even calls to the printer) and doing the following:



Time the executions using the time command:



/usr/bin/time -f "%Uu %Ss %Er %Mkb" vote 100 10 10000 1003
3.21u 0.02s 0:05.67r 32496kb




Output from time differs depending on the shell, so use the system time command. Compare the user (3.21u) and real (0:05.67r) time among runs, which is the CPU time consumed solely by the execution of user code (versus system) and the total time from the start to the end of the program.




If necessary, adjust the number of votes to get real time in range 1 to 100 seconds. (Timing results below 1 second are inaccurate.) Use the same number of votes for all experiments.



Include all 5 timing results to validate your experiments.



Repeat the experiment using 2 processors and include the 5 timing results to validate your exper-iments.



State the performance difference (larger/smaller/by how much) among the monitors/task as the kernel threads increase.



Very briefly speculate on the performance difference, i.e., why is it the same or different.



Use the following to elide output:




#ifdef NOOUTPUT

#define PRINT( stmt )

#else

#define PRINT( stmt ) stmt

#endif // NOOUTPUT




Submission Guidelines







Follow these guidelines carefully. Review the Assignment Guidelines and C++ Coding Guidelines before starting each assignment. Each text or test-document file, e.g., *.{txt,doc} file, must be ASCII text and not exceed 750




length, using the command fold -w120 *.doc | wc -l. Programs should be divided into separate compilation units, i.e., *.{h,cc,C,cpp} files, where applicable. Use the submit command to electronically copy the following files to the course account.




q1*.txt – contains the information required by question 1, p. 1.



BargingCheckVote.h – barging checker (provided)



MPRNG.h – random number generator (provided)



AutomaticSignal.h, q2tallyVotes.h, q2*.{h,cc,C,cpp} – code for question question 2a, p. 1. Program documen-tation must be present in your submitted code. No user, system or test documentation is to be submitted for this question.



q2*.txt – contains the information required by question 2b.



Makefile – construct a makefile similar to those presented in the course to compile the program for ques-tion 2a, p. 1. This makefile must NOT contain hand-coded dependencies. The makefile is invoked as fol-lows:



make vote VIMPL=EXT
vote . . .
make vote VIMPL=INT
vote . . .
make vote VIMPL=INTB
vote . . .
make vote VIMPL=AUTO OUTPUT=OUTPUT
vote . . .
make vote VIMPL=TASK OUTPUT=NOOUTPUT
vote . . .
 CS 343 - Assignment 5
8









Put this Makefile in the directory with the programs, name the source files as specified above, and enter the appropriate make to compile a specific version of the programs. This Makefile must be submitted with the assignment to build the program, so it must be correct. Use the web tool Request Test Compilation to ensure you have submitted the appropriate files, your makefile is correct, and your code compiles in the testing environment.




Follow these guidelines. Your grade depends on it!

More products