Skip to content

Commit

Permalink
Note that the padding is a little arger than it needs to be
Browse files Browse the repository at this point in the history
  • Loading branch information
kuszmaul committed Oct 1, 2024
1 parent 5c3de00 commit cc0434f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion base/locks-mt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ PaddedSpinLocks are padded so that each is guaranteed to be on its own cache lin
false sharing.
"""
mutable struct PaddedSpinLock <: AbstractSpinLock
# we make this much larger than necessary to minimize false-sharing
# We make this much larger than necessary to minimize false-sharing.

# Strictly speaking, this is a little bit larger than it needs to be. For a 64-byte
# cache line, this results in the size being 120 bytes. Because these objects are
# 16-byte aligned, it would be enough if `PaddedSpinLock` was 112 bytes (with 48 bytes
# in the before padding and 56 bytes in the after padding).
_padding_before::NTuple{max(0, CACHE_LINE_SIZE - sizeof(Int)), UInt8}
@atomic owned::Int
_padding_after::NTuple{max(0, CACHE_LINE_SIZE - sizeof(Int)), UInt8}
Expand Down

0 comments on commit cc0434f

Please sign in to comment.