|
|
|
|
|
Access control allows a task to request ownership of one or more resources. In NQC, access control is provided by the acquire statement, which has two forms:
acquire ( resources ) body
acquire ( resources ) body catch handler
where resources is a constant that specifies the resources to be acquired and body and handler are statements. The NQC API defines constants for individual resources which may be added together to request multiple resources at the same time. The behavior of the acquire statement is as follows: Ownership of the specified resources will be requested. If another task of higher priority already owns the resources, then the request will fail and execution will jump to the handler (if present). Otherwise, the request will succeed, and the body will begin to be executed. While executing the body, if another task of equal or higher priority requests any of the owned resources, then the original task will lose ownership. When ownership is lost, execution will jump to the handler (if present). Once the body has completed, the resources will be returned back to the system (so that lower priority tasks may acquire them), and execution will continue with the statement following the acquire statement. If a handler is not specified, then in both the case of a failed request, or a subsequent loss of ownership, control will pass to the statement following the acquire statement. For example, the following code acquires a resource for 10 seconds, playing a sound if it cannot complete successfully:
acquire(ACQUIRE_OUT_A)
{
Wait(1000);
}
catch
{
PlaySound(SOUND_UP);
}
Access control is implemented primarily by the acquire statement. The SetPriority function can be used to set a task's priority, and the following constants may be used to specify resources in an acquire statement.
Constant | Resource
|
---|
ACQUIRE_OUT_A, ACQUIRE_OUT_B, ACQUIRE_OUT_C
| outputs
| ACQUIRE_SOUND | sound
|
|