This module provides basic primitives for creating parallel programs. A Task should be only owned by a single Thread, it cannot be shared by threads.
Example: cmd: --gc:orc
import std/tasks block: var num = 0 proc hello(a: int) = inc num, a let b = toTask hello(13) b.invoke() assert num == 13 # A task can be invoked multiple times b.invoke() assert num == 26 block: type Runnable = ref object data: int var data: int proc hello(a: Runnable) {.nimcall.} = a.data += 2 data = a.data when false: # the parameters of call must be isolated. let x = Runnable(data: 12) let b = toTask hello(x) # error ----> expression cannot be isolated: x b.invoke() let b = toTask(hello(Runnable(data: 12))) b.invoke() assert data == 14 b.invoke() assert data == 16
Procs
proc `=destroy`(t: var Task) {.inline, ...gcsafe, raises: [Exception], tags: [RootEffect].}
- Frees the resources allocated for a Task. Source Edit