Skip to content

Commit 14b8b05

Browse files
authored
doc: update lock example (#36192)
The old example gave the wrong impression that `lock` takes a data structure and not a lock as argument.
1 parent d6b33ea commit 14b8b05

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

doc/src/manual/multi-threading.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,20 @@ can be observed from multiple threads. For example, in most cases you should
7373
use the following code pattern:
7474

7575
```julia-repl
76-
julia> lock(a) do
76+
julia> lock(lk) do
7777
use(a)
7878
end
7979
8080
julia> begin
81-
lock(a)
81+
lock(lk)
8282
try
8383
use(a)
8484
finally
85-
unlock(a)
85+
unlock(lk)
8686
end
8787
end
8888
```
89+
where `lk` is a lock (e.g. `ReentrantLock()`) and `a` data.
8990

9091
Additionally, Julia is not memory safe in the presence of a data race. Be very
9192
careful about reading a global variable (or closure variable) if another thread

0 commit comments

Comments
 (0)