diff options
author | Antoine Delègue <delegue.antoine@gmail.com> | 2024-04-11 09:13:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-11 09:13:17 +0200 |
commit | 2bd2f2885873f5eb2c722b3647fd11ee480a2452 (patch) | |
tree | 51c1319e58a64260299f5573c05ce54f67390185 /lib/system/embedded.nim | |
parent | 9b378296f65fff962225acc1bef2b3811fffda03 (diff) | |
download | Nim-2bd2f2885873f5eb2c722b3647fd11ee480a2452.tar.gz |
Better documentation for typedthreads module (#23483)
Added a second example inside the `typedthreads` file. Also, add a more detailed introduction. When Nim is one's first programming language, a short explanation of what a thread is might not hurt. For reference, the thread documentation of other languages looks like this: - https://en.cppreference.com/w/cpp/thread/thread - https://doc.rust-lang.org/std/thread/ The documentation of a module is the first place one will look when using a standard library feature, so I think it is important to have a few usable examples for the main modules. This is the example added ```nim import locks var l: Lock proc threadFunc(obj: ptr seq[int]) {.thread.} = withLock l: for i in 0..<100: obj[].add(obj[].len * obj[].len) proc threadHandler() = var thr: array[0..4, Thread[ptr seq[int]]] var s = newSeq[int]() for i in 0..high(thr): createThread(thr[i], threadFunc, s.addr) joinThreads(thr) echo s initLock(l) threadHandler() deinitLock(l) ``` Sharing memory between threads is very very common, so I think having an example showcasing this is crucial. --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Diffstat (limited to 'lib/system/embedded.nim')
0 files changed, 0 insertions, 0 deletions