Module thread
Kernel thread primitives.
Class thread
| thread:current () | Gets a thread object representing the current kernel task. |
| thread:run (runtime, name) | Creates and starts a new kernel thread to run a Lua task. |
| thread:shouldstop () | Checks if the current thread has been signaled to stop. |
| thread:stop (self) | Stops a running kernel thread. |
| thread:task (self) | Retrieves information about the kernel task associated with the thread. |
Class thread
Represents a kernel thread object.
- thread:current ()
-
Gets a thread object representing the current kernel task.
If the current task was not created by
thread.run(), the returned object will not have an associated Lunatik runtime.Returns:
-
thread
A thread object for the current task.
Usage:
local t = thread.current()
- thread:run (runtime, name)
-
Creates and starts a new kernel thread to run a Lua task.
The runtime must be sleepable; the script it loaded must return a function,
which becomes the thread body.
Parameters:
- runtime runtime A sleepable Lunatik runtime whose script returns a function.
- name string A descriptive name for the kernel thread.
Returns:
-
thread
A new thread object.
Raises:
Error if the runtime is not sleepable or if thread creation fails.See also:
- thread:shouldstop ()
-
Checks if the current thread has been signaled to stop.
Returns:
-
boolean
trueif the thread should stop,falseotherwise.See also:
Usage:
while not thread.shouldstop() do linux.schedule(100) end
- thread:stop (self)
-
Stops a running kernel thread.
Signals the thread to stop and waits for it to exit.
Parameters:
- self thread thread object to stop.
Returns:
-
nil
Usage:
my_thread:stop() - thread:task (self)
-
Retrieves information about the kernel task associated with the thread.
Parameters:
- self thread thread object.
Returns:
Usage:
local info = my_thread:task()