LOCK/UNLOCK are used to secure (or release) a file for exclusive use. These commands are designed for use on multitasking or network systems to prevent two users or two processes from using the same file at the same time, preventing them from making conflicting transactions.
10 ASSIGN @Path TO "airline.seats"
20 ASSIGN @Travelagency TO 705
30 ENTER @Travelagency;Requested
40 REPEAT
50 LOCK @Path;CONDITIONAL Notlocked
60 Locked= NOT Notlocked
70 UNTIL Locked
80 ENTER @Path;Available,Booked
90 IF Requested>Available THEN
100 UNLOCK @Path
110 OUTPUT @Travelagency;"Only ";Available;" available"
120 ELSE
130 RESET @Path
140 Available=Available-Requested
150 Booked=Booked+Requested
160 OUTPUT @Path;Available,Booked
170 UNLOCK @Path
180 OUTPUT @Travelagency;"OK"
190 END IF
200 ASSIGN @Path TO *
210 END
|