File Sharing Examples

The following is a simple example of a library that allows multiple user processes to access the same disk file. This particular library allows processes to access a file as if it were a stack. In other words, whenever a user process writes to the file, the line pointer is incremented by one. Whenever a user process reads from the file, the line pointer is decremented by one. The PROCURE and LIBERATE statements are used to ensure that only one process accesses the file at a time.

$SHARING = SHAREDBYALL
  BEGIN
    FILE STK(KIND=DISK,MAXRECSIZE=12,BLOCKSIZE=1200);
    EVENT STACK_ACCESS;
    INTEGER TOP_OF_STACK;

    BOOLEAN PROCEDURE PUSH_STK(BUF);
    ARRAY BUF[0];
    BEGIN
      PROCURE(STACK_ACCESS);
      TOP_OF_STACK:= * + 1;
      PUSH_STK:= WRITE(STK[TOP_OF_STACK], 12, BUF);
      LIBERATE(STACK_ACCESS);
    END PUSH_STK;

    BOOLEAN PROCEDURE POP_STK(BUF);
    ARRAY BUF[0];
    BEGIN
      PROCURE(STACK_ACCESS);
      POP_STK:= READ(STK[TOP_OF_STACK], 12, BUF);
      TOP_OF_STACK:= * - 1;
      LIBERATE(STACK_ACCESS);
    END POP_STK;

    EXPORT PUSH_STK, POP_STK;
    OPEN (STK);
    TOP_OF_STACK:= -1;
    FREEZE(PERMANENT);
  END.

The following is an example of a WFL job that uses a global file equation to cause two tasks to use the same logical file. The logical file is declared in the job at lines 140-150. The global file equations occur at lines 190 and 210.

100 ?BEGIN JOB TEST/WFL;
110   JOBSUMMARY = SUPPRESSED;
120   DISPLAYONLYTOMCS = TRUE;
130   CLASS = 0;
140 FILE GBAL(KIND=REMOTE,NEWFILE=TRUE,TITLE=“JUNK/ERRORLOG”,
150           MAXRECSIZE=15,UNITS=WORDS);
160 MYSELF(STATIONNAME = #MYSELF(SOURCENAME));
170 OPEN(GBAL);
180 PROCESS RUN OBJECT/TEST/ALGOL/TASK;
190    FILE BALANCES:= GBAL;
200 PROCESS RUN OBJECT/TEST/ALGOL/TASK;
210    FILE BALANCES:= GBAL;
220 LOCK(GBAL);
230 ?END JOB

Note that, in the preceding WFL job, it is the colon before the equal sign on lines 190 and 210 that informs WFL that this is a global file equation. If the statement were FILE BALANCES = GBAL, then WFL would interpret this as meaning that the file title is GBAL.

The statement at line 160 ensures that the STATIONNAME task attribute of the job reflects the name of the originating station. This STATIONNAME value is inherited by the tasks, and determines the station where the GBAL remote file is opened.

The following is the program that is initiated twice by this WFL job.

100 BEGIN
110 FILE BALANCES;
120 PROCEDURE ERRWRITE(ERR_ARRAY,DEPOSIT,SEQ);
130   EBCDIC ARRAY ERR_ARRAY[*];
140   INTEGER DEPOSIT,SEQ;
150 BEGIN
160   INTEGER CUST_BALANCE;
170   MYJOB.LOCKED:= TRUE;
180   READ(BALANCES[SEQ],//,ERR_ARRAY);
190   CUST_BALANCE:= INTEGER(ERR_ARRAY,8) + DEPOSIT;
200   REPLACE ERR_ARRAY BY CUST_BALANCE FOR 8 DIGITS;
210   WRITE(BALANCES[SEQ],//,ERR_ARRAY);
220   MYJOB.LOCKED:= FALSE;
230 END;
240 % The outer block statements are omitted from this example
250 END.

Because events cannot be declared in WFL, this program is designed to make use of the LOCKED task attribute to regulate access to the file. Setting LOCKED to TRUE has the same effect as procuring an event, and setting LOCKED to FALSE has the same effect as liberating an event. The program uses the MYJOB task variable because this task variable has visibility to all the tasks of the WFL job. This mechanism ensures that only one process is actively reading and writing the file at a time, though all processes continue to have the file open.