Hi,
So basically in simple, the code below is the code with an error:
import std/locks
import system/threads
var
thr: array[2, Thread[string]]
L: Lock
proc SendString(msg: string): void =
L.acquire()
echo msg
L.release()
initLock(L)
for i in 0..len(thr):
if(i == 1): thr[i].createThread(SendString, "hello")
else: thr[i].createThread(SendString, "Goodbye")
joinThreads(thr)
deinitLock(L)
But I really do not get it. What I've done wrong? From what I read in the docs, it has to work right...
# api ref
proc createThread*[TArg](t: var Thread[TArg];
tp: proc (arg: TArg) {.thread, nimcall.}; param: TArg)
the err i get:
template/generic instantiation of `createThread` from here
discard
allocShared0Impl(sizeof(GcThread)))' has no type (or is ambiguous)
import std/locks
var
thr: array[2, Thread[string]]
L: Lock
proc sendString(msg: string): void =
L.acquire()
echo msg
L.release()
initLock(L)
for i in thr.low .. thr.high:
if(i == 1): thr[i].createThread(sendString, "hello")
else: thr[i].createThread(sendString, "Goodbye")
joinThreads(thr)
deinitLock(L)