12 Multiple Task Programming
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?
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.
100 PRINTER IS 8 110 PRINT "HELLO" 120 ENDWhen 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 .
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
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.
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(*))