Source
Edit
Thread support for Nim.
import std/locks
var
thr: array[0..4, Thread[tuple[a,b: int]]]
L: Lock
proc threadFunc(interval: tuple[a,b: int]) {.thread.} =
for i in interval.a..interval.b:
acquire(L)
echo i
release(L)
initLock(L)
for i in 0..high(thr):
createThread(thr[i], threadFunc, (i*10, i*10+5))
joinThreads(thr)
deinitLock(L)
proc createThread(t: var Thread[void]; tp: proc () {.thread, nimcall.}) {.
...raises: [ResourceExhaustedError], tags: [], forbids: [].}
-
Source
Edit
proc createThread[TArg](t: var Thread[TArg];
tp: proc (arg: TArg) {.thread, nimcall.}; param: TArg)
-
Creates a new thread t and starts its execution.
Entry point is the proc tp. param is passed to tp. TArg can be void if you don't need to pass any data to the thread.
Source
Edit
proc getThreadId(): int {....raises: [], tags: [], forbids: [].}
-
Gets the ID of the currently running thread.
Source
Edit
proc joinThread[TArg](t: Thread[TArg]) {.inline.}
-
Waits for the thread t to finish.
Source
Edit
proc pinToCpu[Arg](t: var Thread[Arg]; cpu: Natural)
-
Pins a thread to a CPU.
In other words sets a thread's affinity. If you don't know what this means, you shouldn't use this proc.
Source
Edit