The ALLOW instruction is the opposite of the FORBID function. While FORBID
completely blocks multitasking, ALLOW re-enables it, allowing ugBASIC to schedule
again the execution of other tasks, passing the execution from one task to another
according to its scheduling policy. If a PROCEDURE has previously called FORBID
to assure exclusive access to the CPU, ALLOW returns control to the other procedures,
allowing other procedures to continue execution.
Note that this type of control is "static": in other words, compilation will stop if
the procedure that called FORBID subsequently wants to call a function that
would require multitasking to be active. The call to ALLOW will restore multitasking,
and allow routines of this type to be called.
Once a procedure has finished executing a section of code that required exclusive access
to the processor, it should call ALLOW to allow other tasks to be executed.
If a task needs to wait for an event (for example, a signal), it can call ALLOW before
entering a waiting state, allowing other tasks to execute their code while the waiting task
is suspended.
Using FORBID and ALLOW in a balanced way is essential to achieve both good
performance and correct synchronization between parallel procedures. In many cases,
more sophisticated synchronization mechanisms, such as shared variables, could be used
without completely disabling multitasking.
ALLOW
PARALLEL PROCEDURE test
FORBID
' busy waiting, multitasking is suspended!
FOR i=0 TO 1000: WAIT 1 MS : NEXT i
ALLOW
END PROC
Join BASIC 10Liner Contest with ugBASIC!
An interesting competition is held at the beginning of each year: the
BASIC 10Liner Contest.
It is possible to use ugBASIC to participate in the next
"BASIC10Liner" competition, in the following categories:
ALLOW ↔ Alw
If you have found a problem with this keyword, if you think there is a bug or, more
simply, you would like it to be improved, open an issue for this example on GitHub.
Thank you!
open an issue
BACK TO KEYWORDS