Homework #4

Assigned: October 13
Due: October 20, 4:30pm

Problem

(71 points) [USP] 6.8 Exercise: Barriers on pp. 221-222.

Requirements

You must meet all of the requirements in the problem specification up to, but not including, the penultimate paragraph which starts `Generalize your barrier ...'

As suggested in the problem statement, you can modify the process chain of Program 3.1 on p. 67 or the process fan of Program 3.2 on p. 68 so that it meets the requirements set forth in the application/testing component of this homework described on p. 222. For instance, one approach is to

  1. fork as many children are specified on the command line,
  2. exec the barrierserver in for the parent, and
  3. have each child (client) execute the following
    fprintf(stderr, "i:%d  process ID:%ld  parent ID:%ld  child ID:%ld: just arrived at the first barrier\n",
            i, (long)getpid(), (long)getppid(), (long)childpid);
    
    /* first barrier */
    waitatbarrier("barrier");
    
    fprintf(stderr, "i:%d  process ID:%ld  parent ID:%ld  child ID:%ld: just passed the first barrier\n",
            i, (long)getpid(), (long)getppid(), (long)childpid);
    
    fprintf(stderr, "i:%d  process ID:%ld  parent ID:%ld  child ID:%ld: just arrived at the second barrier\n",
            i, (long)getpid(), (long)getppid(), (long)childpid);
    
    /* second barrier */
    waitatbarrier("barrier");
    
    fprintf(stderr, "i:%d  process ID:%ld  parent ID:%ld  child ID:%ld: just passed the second barrier\n",
            i, (long)getpid(), (long)getppid(), (long)childpid);
    
    This is obviously the process fan approach to the application. Of course if your system is working properly, all of the arrival output messages must proceed any of the passed output messages. Of course, to increase the probability that the server is running before any child attempts to connect to it, after you fork each child, put each child to sleep. By the time each child awakes the server should be running.

    Alternatively, to avoid this problem, a wiser approach is to use a shell script such as:

    #!/bin/ksh
    
    integer num=$1
    integer i=0
    
    # clean up from prior execution
    killall barrierserver
    
    # this killall is unnecessary
    killall bclient
    
    ./barrierserver barrier $num &
    
    while [[ $i -lt $num ]]; do
       #echo $i
       ./bclient $i &
       let i='i+1'
       done
    
    exit 0
    
    which guarantees that the server is running before any child tries to connect to it. However, if you use this preferred approach, you must include a bclient.c, containing a main function to call waitatbarrier twice and produce the appropriate output messages, in your submission.

    Develop a Makefile which builds your system. Your Makefile must include target directives for every derived file produced during the compilation process (i.e., each program, each object file, and any other intermediate files produced during compilation). Make sure that each directive also lists all files on which the derived file depends in its dependency list. Also, your Makefile must be written so carries out only the commands necessary to bring any produced file up-to-date. Your Makefile must do just enough, but no extra, work to bring the final executables for your system up-to-date every time make is invoked. In addition, it must have an all directive and a clean directive to remove all generated files (including the pretty printed Postscript and pdf files). Use variables where appropriate in your Makefile to improve its readability.

    Your Makefile must bring everything up-to-date, using only gcc, without any warnings or errors, when make is invoked on our system.

    How to submit

    Note: All directory and filenames below are case-sensitive. You must use the directory and filenames exactly as shown below (i.e., all lower case).

    Prepare your submission file as /home/<logname>/homeworks/hw4/hw4.tar. This archive must contain

    • a Makefile to build your solution,
    • a README file answering all of the questions asked in the problem statement,
    • the barrier server barrierserver.c,
    • the barrier client barrierclient.c which contains only the definition of the function waitatbarrier,
    • an application barrierapp.c which uses the barrier you develop, or a bclient.c whose executable is called from the application script given above
    • restart.c
    • restart.h, and
    • makeargv.c and makeargv.h.
    Only the file /home/<logname>/homeworks/hw4/hw4.tar will be electronically collected from your account on the deadline.

    Failure to follow these submission requirements will result in a 10% penalty.

    Evaluation

    Eighty percent of your score will come from the correctness of your system, 10% of your score will come from the correctness of your Makefile, and 10% of your score will come from following our programming style guide. Applicable submission penalties will then be applied.


    Return Home