12 Multiple Task Programming

Programming Considerations

When developing or modifying programs to be run on a multiple-user system, consideration should be given to resource management. Such questions should be asked as: should databases be shared or is exclusive access needed? How can a program guarantee that its output is not interrupted by another program?

Once the resource questions are answered, performance needs to be considered. For example, when is instant printer output needed and when can spooling be done? Should the database be updated or will a transaction file be kept?

Resource Management

Resources such as output devices, files, and databases are generally shared. A program requests exclusive access to a resource using one of the Eloquence statements described next. Until the program releases the resource, no other program can use it. If a program requests a resource and the resource is being used exclusively by another program, the request can be queued.

A problem could arise if one program is getting exclusive access to several resources and does not allow other programs to access it. The other programs have to wait. Therefore, a resource should only be requested when it is immediately needed and then should be released after being used.

Another problem is called "deadlock". This occurs when one program has exclusive access to one resource, and then requests access to another. If the other resource is being used exclusively by a second program that then requests the resource locked by the first program, both programs will halt indefinitely.

Output Device Control

Output directed to a CRT is displayed on the terminal from which the program is run.

For example:

120  END
When this sequence is run from the terminal, it prints HELLO on the terminal display.

A printer connected to a terminal (a "local printer") has an address of 10. A printer connected to one terminal cannot be accessed by another terminal. Any terminal can access its own printer and any printers connected directly to the computer.

If several terminals use the same printer and that printer is not spooled, confusion could result if each terminal outputs a line or two. To avoid the confusion, use the REQUEST and RELEASE statements, or use the printer as a spooled device. These statements are fully described in page 249 .

File Access

If more than one program is going to access a file, some handshaking must be done before one program changes data that another program is reading. The ASSIGN statement's class list parameter defines how the file is accessed by each program. ASSIGN is fully described in page 195 . The syntax is listed here for convenience.

ASSIGN # file number TO file spec [,return variable] [;class list]

The access keyword can be EXCLUSIVE, UPDATE or READONLY. If EXCLUSIVE access is requested, only the requesting program can use the file. If another program is already using the file, EXCLUSIVE access is not granted. In UPDATE access, several programs can access the file, but a LOCK must be performed before any writes are allowed to the file. In READONLY access, several programs can access the file but none may update it.

The LOCK and UNLOCK statements are described in page 195 . The syntax and an example using ASSIGN and LOCK are shown here for convenience.

LOCK # file number [,wait variable]

UNLOCK # file number

100  ASSIGN #1 TO "Accnt",Return;UPDATE
110  IF Return=4 THEN GOTO Queue
120  IF Return<>0 THEN GOTO Error
130  Wait=1
140  LOCK #1,Wait
150  ! Read then modify
200  UNLOCK #1

Database Locking

A database may be shared by more than one program, or individual data sets or data items may be locked for exclusive access. (The entire database can also be locked.) All the database statements are described in the Eloquence DBMS Manual. They are summarized here with references to multiple users.


A database may be opened in one of these modes--shared access, exclusive access and read-only access. In shared access mode (mode = 1), multiple users can read from the database. They can modify the database only after locking the data set or data record to be modified. In exclusive access mode (mode = 3), only one user can read from or write to the database. In read-only access mode (mode = 8), many users can read from the database, but none may modify it. Syntax for the DBOPEN statement is as follows:

DBOPEN (base$,pass$,mode,status(*))


The three statements--PREDICATE, DBLOCK and DBUNLOCK--are used together to gain exclusive access of the database or data sets and data items.

The PREDICATE statement is used when more than one data set is to be locked when data items are to be locked. It predefines the data sets and statements to be used by a DBLOCK. These sets and items are referenced by a later DBLOCK by quoting the predicate$ parameter in the DBLOCK statement. Syntax for the PREDICATE statement is as follows:

PREDICATE predicate$ FROM set1$ [ ,item1$ [ ,relop$,value] ]

[ ;set2$ . . . [ ;setn$ . . .] ]

The DBLOCK statement uses the predicate string defined in the PREDICATE statement or a data set name to lock the desired data sets and data items.

The DBUNLOCK statement relinquishes all locks on a database. Syntax for this statement is as follows:

Under the current version of Eloquence, the parameters set, set$, and predicate$ are ignored and the entire database is unlocked. These parameters are reserved for future use.

For example:

100  Base$="DBASE"
110  Pass$="USER"
120  DBOPEN (Base$,Pass$,1,Status(*))
180  Item$="MFG"
190  Set$="COST"
200  PREDICATE Predicate$ FROM Set$,Item$,"<",100
300  DBLOCK (Base$,Predicate$,1,Status(*))
400  DBUNLOCK (Base$,P$,1,Status(*))

Eloquence Language Manual - 19 DEC 2002