AFTER YOU, ALFONSE: A MUTUAL EXCLUSION TOOLKIT
-- An Introduction to BACI
By: Bill Bynum and Tracy Camp
  If neurotic is wanting two mutually exclusive things at one and the same time, then I'm neurotic as hell.
-- Sylvia Plath, 1963

Introduction:  What is BACI?

    Concurrency concepts and synchronization techniques are important issues in computer science.  Due to the increasing emphasis on parallel and distributed computing, understanding concurrency and synchronization is more necessary than ever.  To obtain a thorough understanding of these concepts, practical experience writing concurrent programs is needed.  BACI is an option to obtain this desired ``hands-on'' experience with concurrent programs.

    BACI stands for Ben-Ari Concurrent Interpreter.  The compiler and interpreter originally were procedures in a program written by M. Ben-Ari, based on the original Pascal compiler by Niklaus Wirth.  The original version of the BACI compiler and interpreter was created from that source code and was hosted on a PRIME mainframe.  After several modifications and additions, this version was ported to a PC version in Turbo Pascal, to Sun Pascal, and to C.  Finally, the compiler and interpreter were split into two separate programs.  Recently, a C-- compiler has been added to the BACI suite of programs to compile source programs written in a restricted dialect of C++ into PCODE object code executable by the interpreter.  Compared with other concurrent languages, BACI offers a variety of synchronization techniques with a syntax that is usually familiar.  Any experienced C or Pascal programmer could use BACI within hours.

Back to Top
C-- Compiler Syntax

    BACI's C-- compiler constructs are a subset of C++ compiler constructs.  In other words, C-- follows C/C++ syntax.  Some restrictions and new types are applied, such as:

  1. There are no files other than standard input and output: cout, cin and endl.
  2. Only simple C/C++ types are available in C-- BACI: int and char. Constants (const) of simple types are also supported. (All variables must be declared at the beginning of the code block in which they appear.)
  3. A string type is supported.  BACI also has built-in string handling functions such as: stringCopy, stringCompare, stringConcat etc.
  4. Arrays of simple types and of string type are supported.  Array declaration follows the usual C syntax.
  5. Procedures and functions are supported.  Standard scope rules apply.  Recursion is supported. Parameter declarations are pass-by-value or pass-by-reference.  Execution begins with a call to main().
  6. The executable statements are if-else, switch/case, for, while, do-while, break and continue.  The syntax of these statements is as in standard C/C++.
Back to Top
Concurrency Constructs
 
  1. cobegin

  2.    A list of processes to be run concurrently is enclosed in a cobegin block. Such blocks cannot be nested and must appear in the main program. The PCODE statements belonging to the listed procedures are interleaved by the interpreter in an arbitrary, 'random' order, so that multiple executions of the same program containing a cobegin block will appear to be non-deterministic.  The main program is suspended until all of the processes in the cobegin block terminate, at which time execution of the main program resumes at the statement following the ending of the block.  Here is an example:

        cobegin {
            proc1( ... ); proc2( ... ); ... ; procN( ... );
        }
     

  3. semaphores

  4.     semaphore is a predeclared type in BACI.  It is a non-negative valued int variable that can be accessed only in restricted ways.  BACI also has binarysem subtype which is binary semaphore, one that only assumes the values 0 and 1.  Semaphore functions includes:  
  5. monitors

  6.     BACI also supports Hoare's monitor concept with some restrictions.  A monitor is a C-- block with some additional properties.  All functions in the monitor variables are visible from the outside, but the monitor variables are not accessible outside of the block and can only be accessed by the monitor functions.  In BACI, a monitor can be declared only at the outermost, global lever.  Monitors can not be nested.  Only one procedure or function of the monitor block can execute at any one time.  This feature makes it possible to use monitors to implement mutual exclusion.  Three constructs are used by procedures and functions of a monitor to control concurrency: condition variables, waitc (wait on condition), and signalc (signal a condition).  
  7. other concurrency constructs
Back to Top
Using BACI

    A BACI source file using the C-- compiler should use a .cm suffix.  To execute a program in BACI, there are two steps:

  1. Compile a ".cm" file to obtain a PCODE file (.pco)

  2. Usage:  bacc [optional_flags] source_filename
    Optional_flags:
      -h show this help
      -c make a .pob object file for subsequent linking
     
  3. Interpret a PCODE file (.pco) to execute the program

  4. Usage bainterp [optional_flags] pcode_filename
    Optional_flags:
      -d enter the debugger, single step, set breakpoints
      -e show the activation record (AR) on entry to each process
      -x show the AR on exit from each process
      -t announce process termination
      -h show this help
      -p show PCODE instructions as they are executed
    There is a shell script, baccint, that will call the compiler and then call the interpreter for you. It passes the options that you give it along to the interpreter. If you are using the Pascal compiler syntax, then the source file should be with a .pm suffix, and you compile the program with the bapas compiler.
 
Back to Top
Examples
 
    The following listing was produced by the C-- BACI compiler. The number to the right of the line number is the PCODE offset of the instruction begins that line.  The BACI compiler creates this listing from the file "incremen.cm". The listing is placed in the file "increment.lst". An "incremen.pco" file is also created; this file is used by the interpreter.     The following listing was produced by the BACI interpreter.  The interpreter executes the program  that was compiled into the file "incremen.pco". Obtain a Copy

    Currently, the BACI system can be compiled in Linux, RS/6000 AIX, Sun OS, SGI IRIX, and DOS with minimal modifications to the Makefile file.  If you use different hardware platform than these, and if you can give us access to your hardware, we will try to install the BACI system for your machine type.  We can be reached at bynum@cs.wm.edu or tcamp@mines.edu.
   Click on one of the following files to download:

If you decide to use BACI in one of your courses, please let us know! Past updates to the BACI system are archived.
Back to Top
Where is BACI being used?

    BACI has been used numerous times in courses by the two authors at the College of William and Mary, the Colorado School of Mines, and the University of Alabama. In addition, it is being used (or has been used) at: the Sistema ITESM in Mexico, the University of Dundee in Scotland, University of Luton in England, University of Cyprus in Cyprus, Technical University of Sofia in Bulgaria, Universita' Ca' Foscari di Venezia in Italy, Central Queensland University, Queensland University of Technology, and Australian Catholic University in Australia, Universidad de Oviedo, University of Cordoba, and ITESM Campus Leon in Spain, Eastern Institute of Technology in New Zealand, Satya Wacana Christian University in Indonesia, and Penn State Harrisburg, Muhlenberg College, St. Norbert College, Saint Xavier University, Roberts Wesleyan College, Boston University, Lock Haven University, St. John's University, Xavier University of Louisiana, University of Maine at Farmington, Worcester State College, and The University of Texas at El Paso in the United States. Please let us know if you are using BACI at your university.

Back to Top

Last modified: Wed Sep 1 10:18:26 MDT 1999

Comments | Camp's Home | MACS Home | Mines Home