Skip to content

Commit 82fe11f

Browse files
committed
Make next_id() thread-safe
1 parent 4f6575d commit 82fe11f

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/thunk.jl

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
export Thunk, delayed, delayedmap
22

3-
# TODO: Make this thread-safe
4-
let counter=0
5-
global next_id
6-
next_id() = (counter >= (1 << 30)) ? (counter = 1) : (counter += 1)
7-
end
3+
const ID_COUNTER = Threads.Atomic{Int}(1)
4+
next_id() = Threads.atomic_add!(ID_COUNTER, 1)
85

96
"""
107
Thunk

0 commit comments

Comments
 (0)