Skip to content

Commit 56d307f

Browse files
tkfstaticfloat
authored andcommitted
Fix a concurrency bug in iterate(::Dict) (#44534)
(cherry picked from commit 6be86a3)
1 parent 90c4fd8 commit 56d307f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

NEWS.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,13 @@ New library functions
102102
* New function `Base.rest` for taking the rest of a collection, starting from a specific
103103
iteration state, in a generic way ([#37410]).
104104

105-
New library features
106-
--------------------
105+
Library changes
106+
---------------
107+
108+
* A known concurrency issue of `iterate` methods on `Dict` and other derived objects such
109+
as `keys(::Dict)`, `values(::Dict)`, and `Set` is fixed. These methods of `iterate` can
110+
now be called on a dictionary or set shared by arbitrary tasks provided that there are no
111+
tasks mutating the dictionary or set ([#44534]).
107112

108113
* The `redirect_*` functions now accept `devnull` to discard all output redirected to it, and as an empty
109114
input ([#36146]).

base/dict.jl

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

684684
@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)
685685
@propagate_inbounds function iterate(t::Dict)
686-
_iterate(t, skip_deleted_floor!(t))
686+
_iterate(t, skip_deleted(t, t.idxfloor))
687687
end
688688
@propagate_inbounds iterate(t::Dict, i) = _iterate(t, skip_deleted(t, i))
689689

0 commit comments

Comments
 (0)