CS 471

Assignmnet #3

Due Midnight, Thursday March 22, 2012

 

Write the following program (you may use C, C++ or Java)

 

The program creates two types of threads:  Submit & Review interacting via a common Board.

There are:

9 Submit threads,

9 Review threads and

9 Board Slots.

 

ê The Borad:

A board  slot has two fields: S and R.

          for i = 1 to 9 {

                 S[i]  =  0

                 R[i]  =  0

          }

 

ê Submit thread  I  (1, ...9):

while (true) {

generate a random number J between 1 and 9

sleep J seconds

if (S [J] == 0) {

    S[J] = I

   display content of Board

   exit

}

}

 

ê Review thread  I  (1, ...9):

while (true) {

generate a random number J between 1 and 9

sleep J seconds

if  (S[J] !=0)   &  (R[J]  == 0) {

      S[J] = I

      display content of Board

      if last thread: display threads statistics ( #trails to find a slot &  time to finish).

      exit

}

}

 

Usage Syntax:

 

% SubRev

 

         You may execute my solution at:

http://www.cs.odu.edu/~cs471w/spring12/assignments/a3/wahab

EXAMPLE:

 

[antares] ~/public_html/spring12/assignments/a3/wahab> SubRev

  

See  SamplOutputs  File