Skip to content

Commit

Permalink
Fix a concurrency bug in iterate(::Dict) (#44534)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf authored Mar 12, 2022
1 parent 5ec1f9f commit 6be86a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ Build system changes
New library functions
---------------------

Library changes
---------------

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


Standard library changes
Expand Down
2 changes: 1 addition & 1 deletion base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ end

@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)
@propagate_inbounds function iterate(t::Dict)
_iterate(t, skip_deleted_floor!(t))
_iterate(t, skip_deleted(t, t.idxfloor))
end
@propagate_inbounds iterate(t::Dict, i) = _iterate(t, skip_deleted(t, i))

Expand Down

0 comments on commit 6be86a3

Please sign in to comment.