[backport] Clarifies experimental / parallel example on manual.rst (#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.
This commit is contained in:
parent
b03de8a4d9
commit
d731646106
1 changed files with 7 additions and 1 deletions
|
|
@ -6371,12 +6371,18 @@ is uncertain (it may be removed any time).
|
|||
Example:
|
||||
|
||||
.. code-block:: nim
|
||||
import threadpool
|
||||
{.experimental: "parallel".}
|
||||
|
||||
proc threadedEcho(s: string, i: int) =
|
||||
echo(s, " ", $i)
|
||||
|
||||
proc useParallel() =
|
||||
parallel:
|
||||
for i in 0..4:
|
||||
echo "echo in parallel"
|
||||
spawn threadedEcho("echo in parallel", i)
|
||||
|
||||
useParallel()
|
||||
|
||||
|
||||
As a top level statement, the experimental pragma enables a feature for the
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue