Skip to content

Commit abe23d2

Browse files
committed
Fix concurrency bug
1 parent 7fbac1c commit abe23d2

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.9.7
2+
3+
Fix a concurrency bug, where Libtask would sometimes crash with a "Multiple concurrent writes to Dict detected!" error when TapedTasks were being executed concurrently.
4+
15
# 0.9.6
26

37
Add support for Julia v1.12.

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ uuid = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f"
33
license = "MIT"
44
desc = "Tape based task copying in Turing"
55
repo = "https://github.com/TuringLang/Libtask.jl.git"
6-
version = "0.9.6"
6+
version = "0.9.7"
77

88
[deps]
99
MistyClosures = "dbe65cb8-6be2-42dd-bbc5-4196aaced4f4"

src/copyable_task.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,18 @@ struct CacheKey
113113
key::Any
114114
end
115115

116-
const mc_cache = Dict{CacheKey,MistyClosure}()
116+
struct GlobalMCCache
117+
cache::Dict{CacheKey,MistyClosure}
118+
lock::ReentrantLock
119+
120+
GlobalMCCache() = new(Dict{CacheKey,MistyClosure}(), ReentrantLock())
121+
end
122+
123+
Base.haskey(c::GlobalMCCache, key) = haskey(c.cache, key)
124+
Base.getindex(c::GlobalMCCache, key) = getindex(c.cache, key)
125+
Base.setindex!(c::GlobalMCCache, val, key) = @lock c.lock setindex!(c.cache, val, key)
126+
127+
const mc_cache = GlobalMCCache()
117128

118129
"""
119130
TapedTask(taped_globals::Any, f, args...; kwargs...)

0 commit comments

Comments
 (0)