From d731646106323537f4315279da5b62484bbc45b7 Mon Sep 17 00:00:00 2001 From: UNIcodeX Date: Thu, 24 Oct 2019 07:08:27 -0500 Subject: [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 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. --- doc/manual.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'doc') diff --git a/doc/manual.rst b/doc/manual.rst index 3a4dc77d8..d1fa1ba07 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -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 -- cgit 1.4.1-2-gfad0