Assignment 5

Interprocess Communication - II

use: shared memory, semaphores, light weight threads,
heavy weight processes, signals and signal handlers
(do not use fifos, pipes and message queues)
  

This is a group assignment (2 students/group).
Form your groups.
 

------------------------------------------------------------------------------

Synchronization Problem: The Game of Cricket

Design an experiment that implements the game of cricket as follows:

There are 3 members per cricket team.
There are two processes P1 and P2, that represent the two teams.
Each process has three threads representing its team members.

In the fielding team, everyone has to bowl an over of 3 balls.
Once the bowler bowls, the batsman (randomly) either (i) looses the wicket
or (ii) scores runs (0..6: random) by hitting
the ball towards one of the fielders (randomly selected).
The fielder then returns the ball to the bowler, after which the
bowler continues with the over.
The batsmen interchange their sides after every over. If a batsman hits
odd number of runs, the batsmen interchange. If a batsman gets out, another steps in, i.e.
the corresponding thread wakes up.

After one side bats, the batting and fielding roles are interchanged.
Subsequently the final winner is decided.

Start working on the assignment in the next regular lab session,
at the end of which, you will be submitting an electronic report
using the submit program. The report should describe the algorithm
and its implementation guidelines. Actual working code may be
submitted on or before Monday 21st August.
Utilize the lab session to  equip yourself with the os system calls
that are required to implement your synchronization scheme.

note: You must trap the control-c and provide a signal handler to perform graceful
exit, i.e. to close down the entire  match by cleaning up all threads, and IPC structures.