0

I just copy the code from the example on nim's offical documentation:

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) # lock stdout
    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)
$ nimble build --threads:on
Verifying dependencies for thread@0.1.0
Building thread/thread.exe using c backend
$ .\thread

then thread.exe crashed...

 thread.exe 
   0.0.0.0 
   630c5e83 
   libwinpthread-1.dll 
   6.3.9600.20512 
   62cdfc6e 
   c0000135 
   00000000000ed1b0 
   1fc8 
   01d8bb71e28918ba 
   F:\MyProjects\Nim\thread\thread.exe 
   libwinpthread-1.dll 
   2044d161-2765-11ed-827a-6c86063c07b4 

I have no ideas about it...Can anybody help me? Thanks a lot.

LingC
  • 1
  • 2

1 Answers1

0

Gave it a try in Windows 8.1, it does fail.

Apparently is a recent regression in nim you can make it work if you compile it with --threads:on --tlsEmulation:on (or make sure mingw binaries is on your PATH).

cyraxjoe
  • 5,661
  • 3
  • 28
  • 42