15.1 Threads
A thread is a concurrent thread of evaluation. Rhombus schedules threads preemptively, but conceptually on the same physical processor as a coroutine thread by default; coroutine threads provide concurrency, but not parallelism. Create a parallel thread by specifying a parallel thread pool when creating the thread. Threads can communicate via shared state, and they can synchronize using semaphores or other synchronizable events.
A Thread object is itself a synchronizable event that is ready for synchronization when the thread has terminated. The synchronization result is just the thread object itself.
class | ||||||||
| ||||||||
| ||||||||
expression | ||||||||
| ||||||||
| ||||||||
| ||||||||
| ||||||||
enumeration | ||||||||
If pool is #false, then the thread is created as a coroutine thread. If pool is a Thread.Pool, then the thread is created as a parallel thread in the given pool. Supplying #'own as pool is equivalent to supplying Thread.Pool(1), but also closing the pool with Thread.Pool.close immediately after the new thread is added.
If keep is #false, then the result of thunk is ignored. If keep is #'results, then the results from thunk are saved and returned by Thread.wait on the thread.
A thread: body; ... form is equivalent to Thread(fun (): body; ...). Using a ~pool or ~keep option in thread is the same as passing the corresponding argument to the Thread constructor.
A Thread object satisfies Evt and includes the Evt.sync method.
If the thread completes normally—
If the thread does not complete normally, then fail_k is called in tail position, so its results are the results of Thread.wait.
> def th:
~keep: #'results
1 + 2
3
method | ||||
| ||||
| ||||
enumeration | ||||
function | |
|
class | ||
| ||
| ||
method | ||
| ||
value | ||
|
A thread can be added to a pool as long as the pool is still open. After Thread.Pool.close is called on a pool, no new threads can be added to the pool, and the pool’s resources are released back to the system a threads already within the pool terminate.
The Thread.Pool.own value #'own is useful with ~pool in thread.
function | |
property | |
| |
| |
function | |
|