Skip to content

Commit

Permalink
improve atomic docs (JuliaLang#42024)
Browse files Browse the repository at this point in the history
* improve atomic docs

* Update base/docs/basedocs.jl

Co-authored-by: Jameson Nash <vtjnash@gmail.com>

* Update base/docs/basedocs.jl

Co-authored-by: Jameson Nash <vtjnash@gmail.com>

Co-authored-by: Jameson Nash <vtjnash@gmail.com>
  • Loading branch information
2 people authored and LilithHafner committed Feb 22, 2022
1 parent 4277e0d commit 80dd79e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2003,24 +2003,23 @@ setfield!
These atomically perform the operations to simultaneously get and set a field:
y = getfield!(value, name)
y = getfield(value, name)
setfield!(value, name, x)
return y
```
"""
swapfield!

"""
modifyfield!(value, name::Symbol, op, x, [order::Symbol])
modifyfield!(value, i::Int, op, x, [order::Symbol])
modifyfield!(value, name::Symbol, op, x, [order::Symbol]) -> Pair
modifyfield!(value, i::Int, op, x, [order::Symbol]) -> Pair
These atomically perform the operations to get and set a field after applying
the function `op`.
y = getfield!(value, name)
y = getfield(value, name)
z = op(y, x)
setfield!(value, name, z)
return y, z
return y => z
If supported by the hardware (for example, atomic increment), this may be
optimized to the appropriate hardware instruction, otherwise it'll use a loop.
Expand All @@ -2029,18 +2028,19 @@ modifyfield!

"""
replacefield!(value, name::Symbol, expected, desired,
[success_order::Symbol, [fail_order::Symbol=success_order]) =>
(old, Bool)
[success_order::Symbol, [fail_order::Symbol=success_order]) -> (; old, success::Bool)
replacefield!(value, i::Int, expected, desired,
[success_order::Symbol, [fail_order::Symbol=success_order]) -> (; old, success::Bool)
These atomically perform the operations to get and conditionally set a field to
a given value.
y = getfield!(value, name, fail_order)
y = getfield(value, name, fail_order)
ok = y === expected
if ok
setfield!(value, name, desired, success_order)
end
return y, ok
return (; old = y, success = ok)
If supported by the hardware, this may be optimized to the appropriate hardware
instruction, otherwise it'll use a loop.
Expand Down

0 comments on commit 80dd79e

Please sign in to comment.