I have code in the following general form:
while ...:
createThread(...)
...
joinThreads(...)
It works the first iteration, but the threads don't seem to start on the 2nd iteration. Is there any reason/workaround for this?
One obvious workaround would be to make the threads global, so they only have to be started once. However, the general structure of the program is something like
A
B
C
A
B
C
...
where threads will be doing something different in A, B and C -- so having to have all threads global requires a good bit more complexity.
EDIT
One answer would be to use spawn and not createThread. But I am using channels, and http://forum.nim-lang.org/t/959 recommends using createThread in this case. I have threads of different types doing different tasks (and talking with each other) -- so unless it were possible to partition the thread pool, it would seem that I need more control than "spawn" provides.
(NB -- this all fits into a "bulk synchronous parallel" architecture with multiple reduce steps -- I'm sure there is a higher-level library that would help here. :))
BTW -- one workaround I have found: variables of type Thread (it seems) can't be reused, but they can be local. So
while ...:
proc foo() =
createThread(...)
...
joinThread(...)
foo()
will work.As always, PRs are welcome.