For the latest stable version, please use Emilua API 0.10! |
this_fiber
Object referring to current fiber.
this_fiber is a global so it doesn’t need to be require() d.
|
Functions
yield()
Reschedule current fiber to be executed in the next round so other ready fibers have a chance to run now. You usually don’t need to call this function as any suspending function already do that.
{forbid,allow}_suspend()
forbid_suspend()
allow_suspend()
A call to forbid_suspend()
will put the fiber in the state of
suspension-disallowed and any attempt to suspend the fiber while it is in this
state will raise an error.
forbid_suspend()
may be called multiple times. A matching number of calls to
allow_suspend()
will put the fiber out of the suspension-disallowed
state. You must not call allow_suspend()
if there was no prior call to
forbid_suspend()
.
These functions aren’t generally useful and they would have no purpose in
preemptive multitasking. However a cooperative multitasking environment offers
opportunities to avoid some round-trips to sync primitives. These opportunities
shouldn’t really be used and the programmer should just rely on the classical
sync primitives. However I can’t tame every wild programmer out there so there
is this mechanism to at least document the code in mechanisms similar to
assert()
statements from native languages.
They’re only useful if there are comprehensive test cases. Still, the use of these functions may make the code more readable. And some tools may be developed to understand these blocks and do some simple static analysis.