Skip to content

Commit b3dde45

Browse files
tkfKristofferC
authored andcommitted
Fix a concurrency bug in iterate(::Dict) (#44534)
(cherry picked from commit 6be86a3)
1 parent 51f8ac2 commit b3dde45

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ New library functions
9797
New library features
9898
--------------------
9999

100+
* A known concurrency issue of `iterate` methods on `Dict` and other derived objects such
101+
as `keys(::Dict)`, `values(::Dict)`, and `Set` is fixed. These methods of `iterate` can
102+
now be called on a dictionary or set shared by arbitrary tasks provided that there are no
103+
tasks mutating the dictionary or set ([#44534]).
100104
* `@time` and `@timev` now take an optional description to allow annotating the source of time reports,
101105
e.g. `@time "Evaluating foo" foo()` ([#42431]).
102106
* `range` accepts either `stop` or `length` as a sole keyword argument ([#39241]).

base/dict.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ end
702702

703703
@propagate_inbounds _iterate(t::Dict{K,V}, i) where {K,V} = i == 0 ? nothing : (Pair{K,V}(t.keys[i],t.vals[i]), i == typemax(Int) ? 0 : i+1)
704704
@propagate_inbounds function iterate(t::Dict)
705-
_iterate(t, skip_deleted_floor!(t))
705+
_iterate(t, skip_deleted(t, t.idxfloor))
706706
end
707707
@propagate_inbounds iterate(t::Dict, i) = _iterate(t, skip_deleted(t, i))
708708

0 commit comments

Comments
 (0)