Yield (YIELD)
Instruction Syntax
Op Code (Hex) |
---|
0610 |
Bound Program Access |
---|
|
Description:
The dispatching algorithm is run. If another thread of equal or higher priority is eligible to run, then a thread is chosen and dispatched. Otherwise, the current thread resumes execution.
Usage Notes
The yield() function is a common technique used on other platforms to serialize on a resource or to allow other threads of equal or higher priority to execute before the current thread begins execution of a long running function.
- Serialization of a resource
A "spin" lock is a high speed synchronization primitive in which the application "loops" on the setting of a variable which is used to synchronize access to a resource. A typical application implementation of a spin lock might be:
- Compare and swap on a variable that synchronizes access to a resource.
- If not available and first time in loop, invoke the yield() function.
- Otherwise if not the first time in loop, wait for a small time quantum. This time quantum is incremented each time through the loop.
- Loop back to the compare and swap statement.
- Allow threads of equal or higher priority to run
The yield() function allows a thread to immediately relinquish control to a thread of equal or higher priority. On other platforms, this is done because the kernel can not (usually) be preempted. On IBM i, the duration of time another thread of equal or higher priority may be prevented from executing until the current thread reaches time-slice end is considered to be very large, especially considering the processing speeds of current machines.
Authorization Required
- None
Lock Enforcement
- None
Exceptions
- None