ALLOW
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.
PARALLEL PROCEDURE test FORBID ' busy waiting, multitasking is suspended! FOR i=0 TO 1000: WAIT 1 MS : NEXT i ALLOW END PROC
Alw
If you have encountered a problem using this command, if you think there is a bug or the explanation is unclear, please open an issue for this keyword on GitHub. Thank you!