Skip to content

Commit 83bd0a1

Browse files
committed
use acquire-release ordering
Thanks vtjnash! #45 (comment)
1 parent 194dbe0 commit 83bd0a1

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

src/Perms/perm_images.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,36 +44,36 @@ AP.__unsafe_image(n::Integer, σ::Perm) = oftype(n, @inbounds σ.images[n])
4444
function Base.copy(p::Perm)
4545
imgs = copy(p.images)
4646
q = typeof(p)(imgs; check = false)
47-
if isdefined(p, :inv, :sequentially_consistent)
48-
inv_imgs = copy(@atomic(p.inv).images)
47+
if isdefined(p, :inv, :acquire)
48+
inv_imgs = copy(p.inv.images)
4949
q⁻¹ = typeof(p)(inv_imgs; check = false)
50-
@atomic q.inv = q⁻¹
51-
@atomic q⁻¹.inv = q
50+
@atomic :release q⁻¹.inv = q
51+
@atomiconce :release :acquire q.inv = q⁻¹
5252
end
5353
return q
5454
end
5555

5656
function Base.inv::Perm)
57-
if !isdefined(σ, :inv, :sequentially_consistent)
57+
if !isdefined(σ, :inv, :acquire)
5858
if isone(σ)
59-
@atomic σ.inv = σ
59+
@atomiconce :release :acquire σ.inv = σ
6060
else
6161
σ⁻¹ = typeof(σ)(invperm.images); check = false)
62-
# we don't want to end up with two copies of inverse σ floating around
63-
if !isdefined(σ, :inv, :sequentially_consistent)
64-
@atomic σ.inv = σ⁻¹
65-
@atomic σ⁻¹.inv = σ
66-
end
62+
# this order is important:
63+
# fuly initialize the "local" inverse first and only then
64+
# update σ to make the local inverse visible globally
65+
@atomic :release σ⁻¹.inv = σ
66+
@atomiconce :release :acquire σ.inv = σ⁻¹
6767
end
6868
end
6969
return σ.inv
7070
end
7171

7272
function AP.cycles::Perm)
73-
if !isdefined(σ, :cycles, :sequentially_consistent)
73+
if !isdefined(σ, :cycles, :acquire)
7474
cdec = AP.CycleDecomposition(σ)
7575
# we can afford producing more than one cycle decomposition
76-
@atomic σ.cycles = cdec
76+
@atomiconce :release :acquire σ.cycles = cdec
7777
end
7878
return σ.cycles
7979
end

src/group_interface.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
Base.one(G::PermGroup{P}) where {P} = Permutation(one(P), G)
44

55
function GroupsCore.order(::Type{T}, G::AbstractPermutationGroup) where {T}
6-
if !isdefined(G, :order, :sequentially_consistent)
7-
ord = order(StabilizerChain(G))
8-
@atomic G.order = ord
6+
if !isdefined(G, :order, :acquire)
7+
ord = order(BigInt, StabilizerChain(G))
8+
@atomiconce :release :acquire G.order = ord
99
end
1010
return convert(T, G.order)
1111
end

src/perm_group.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,9 @@ The subsequent calls just return the cached data structure.
9090
"""
9191

9292
function StabilizerChain(G::PermGroup{P,T}) where {P,T}
93-
if !isdefined(G, :stabchain, :sequentially_consistent)
93+
if !isdefined(G, :stabchain, :acquire)
9494
stabchain = schreier_sims(T, __gens_raw(G))
95-
# this may take some time, so let's check again
96-
if !isdefined(G, :stabchain, :sequentially_consistent)
97-
@atomic G.stabchain = stabchain
98-
end
95+
@atomiconce :release :acquire G.stabchain = stabchain
9996
end
10097
return G.stabchain
10198
end

0 commit comments

Comments
 (0)