New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarifies experimental / parallel example on manual.rst #12472
Conversation
Details: Calling `useParallel()` in example fails with compiler error Error: 'parallel' section without 'spawn' Adding `spawn` causes error: Error: internal error: (filename: "ccgexprs.nim", line: 1032, column: 17) No stack traceback available To create a stacktrace, rerun compilation with ./koch temp c <file> Therefore a separate proc, `threadedEcho`, is added for the echo'ing of the string, which allows the example to build, however, `sync()` must be added so that the "echo in parallel" strings will actually be shown on the terminal. Otherwise, the program will spawn of the threads and exit before they can return to the main thread.
Observation: Sometimes without It may be good, for illustrative purposes of the example, to actually expand a bit further and output the thread number, illustrating that threads spawned later may return before threads spawned earlier. import threadpool, strformat
{.experimental: "parallel".}
proc threadedEcho(s: string, i: int) =
echo(fmt"'{s}' for thread # {i}")
proc useParallel() =
parallel:
for i in 0..4:
spawn threadedEcho("echo in parallel", i)
sync()
useParallel() Which, in my testing, yields something like this:
|
|
I've ran it several more times without the What about the rest?? |
Merge remote-tracking branch 'upstream/devel' into devel
Issue: Calling useParallel() in example failed with compiler error `Error: 'parallel' section without 'spawn'` Adding spawn yielded compiler error: ```bash Error: internal error: (filename: "ccgexprs.nim", line: 1032, column: 17) No stack traceback available To create a stacktrace, rerun compilation with ./koch temp c ``` Proposed Solution: - Separate proc, threadedEcho, is added for the echo'ing of the string, which allows the example to build - Added the thread number so that it can demonstrate that sometimes threads which were started sooner, come back after threads which were started later.
Removed Added output of thread number. import threadpool
{.experimental: "parallel".}
proc threadedEcho(s: string, i: int) =
echo(s, " ", $i)
proc useParallel() =
parallel:
for i in 0..4:
spawn threadedEcho("echo in parallel", i)
useParallel() example output:
|
…12472) * Clarifies experimental / parallel on manual.rst Details: Calling `useParallel()` in example fails with compiler error Error: 'parallel' section without 'spawn' Adding `spawn` causes error: Error: internal error: (filename: "ccgexprs.nim", line: 1032, column: 17) No stack traceback available To create a stacktrace, rerun compilation with ./koch temp c <file> Therefore a separate proc, `threadedEcho`, is added for the echo'ing of the string, which allows the example to build, however, `sync()` must be added so that the "echo in parallel" strings will actually be shown on the terminal. Otherwise, the program will spawn of the threads and exit before they can return to the main thread. * Fixes and clarifies example for threading in manual.rst Issue: Calling useParallel() in example failed with compiler error `Error: 'parallel' section without 'spawn'` Adding spawn yielded compiler error: ```bash Error: internal error: (filename: "ccgexprs.nim", line: 1032, column: 17) No stack traceback available To create a stacktrace, rerun compilation with ./koch temp c ``` Proposed Solution: - Separate proc, threadedEcho, is added for the echo'ing of the string, which allows the example to build - Added the thread number so that it can demonstrate that sometimes threads which were started sooner, come back after threads which were started later. (cherry picked from commit d731646)
Details:
Calling
useParallel()
in example fails with compiler errorError: 'parallel' section without 'spawn'
Adding
spawn
causes error:Error: internal error: (filename: "ccgexprs.nim", line: 1032, column: 17)
No stack traceback available
To create a stacktrace, rerun compilation with ./koch temp c
Therefore a separate proc,
threadedEcho
, is added for the echo'ingof the string, which allows the example to build, however,
sync()
must be added so that the "echo in parallel" strings will actually
be shown on the terminal. Otherwise, the program will spawn of the
threads and exit before they can return to the main thread.