diff --git a/docs/92-false-sharing.md b/docs/92-false-sharing.md index 7aba6e8..22e1f4f 100644 --- a/docs/92-false-sharing.md +++ b/docs/92-false-sharing.md @@ -96,7 +96,7 @@ So how do we solve false sharing? There are two main solutions. The first solution is to use the same approach we’ve shown but ensure that `sumA` and `sumB` aren’t part of the same cache line. For example, we can update the `Result` struct to add _padding_ between the fields. Padding is a technique to allocate extra memory. Because an `int64` requires an 8-byte allocation and a cache line 64 bytes long, we need 64 – 8 = 56 bytes of padding: -```go +```go hl_lines="3" type Result struct { sumA int64 _ [56]byte // Padding diff --git a/site/92-false-sharing/index.html b/site/92-false-sharing/index.html index 536102a..0cf5994 100644 --- a/site/92-false-sharing/index.html +++ b/site/92-false-sharing/index.html @@ -924,8 +924,8 @@
The first solution is to use the same approach we’ve shown but ensure that sumA and sumB aren’t part of the same cache line. For example, we can update the Result struct to add padding between the fields. Padding is a technique to allocate extra memory. Because an int64 requires an 8-byte allocation and a cache line 64 bytes long, we need 64 – 8 = 56 bytes of padding:
type Result struct {
sumA int64
- _ [56]byte // Padding
- sumB int64
+ _ [56]byte // Padding
+ sumB int64
}
The next figure shows a possible memory allocation. Using padding, sumA and sumB will always be part of different memory blocks and hence different cache lines.