1125064645637738496

This commit is contained in:
ed committed 2026-08-27 19:32:03 -04:00
1 parent d1f0d6d1b8
commit 60b5b85db8
4 files changed
+124

No files matched your search

@@ -0,0 +1,41 @@
---
title: "@SebAaltonen @stewartmoss , nice code up above."
type: archive
source: twitter
source_url: "https://x.com/AndrewJacksonZA/status/1125101399258353665"
author: "Andrew Jackson"
handle: AndrewJacksonZA
post_id: "1125101399258353665"
date: 2019-05-05
archived: 2026-08-27
draft: false
tags:
- archive
- twitter
- SebAaltonen
description: "@SebAaltonen @stewartmoss , nice code up above."
in_reply_to: ""
parent_post_id: "1125067183476944896"
---
## Source
- URL: https://x.com/AndrewJacksonZA/status/1125101399258353665
- Author: Andrew Jackson (@AndrewJacksonZA)
- Posted: 2019-05-05 18:14:11
## Branch
**1/** **@AndrewJacksonZA** ^1125101399258353665
**@SebAaltonen** **@stewartmoss**
, nice code up above.
Also: https://x.com/SebAaltonen/status/1125075962524262403
/CC @STEMsubsistence and @KeithPlaysPC , because exposure to/learning cool out-of-one's-depth stuff is sometimes extremely valuable. :-)
## Related
- Spine: [[archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two]]
@@ -0,0 +1,37 @@
---
title: "@SebAaltonen It's missing exponential backoff for mm_pause though"
type: archive
source: twitter
source_url: "https://x.com/lectem/status/1125076786520514563"
author: "Clément Grégoire"
handle: lectem
post_id: "1125076786520514563"
date: 2019-05-05
archived: 2026-08-27
draft: false
tags:
- archive
- twitter
- SebAaltonen
description: "@SebAaltonen It's missing exponential backoff for mm_pause though"
in_reply_to: ""
parent_post_id: "1125067183476944896"
---
## Source
- URL: https://x.com/lectem/status/1125076786520514563
- Author: Clément Grégoire (@lectem)
- Posted: 2019-05-05 16:36:23
## Branch
**1/** **@lectem** ^1125076786520514563
**@SebAaltonen**
It's missing exponential backoff for mm_pause though
## Related
- Spine: [[archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two]]
@@ -0,0 +1,44 @@
---
title: "This is how you write a good x64 spinlock: Use two stage construct."
type: archive
source: twitter
source_url: "https://x.com/SebAaltonen/status/1125064645637738496"
author: "Sebastian Aaltonen"
handle: SebAaltonen
post_id: "1125064645637738496"
date: 2019-05-05
archived: 2026-08-27
draft: false
tags:
- archive
- twitter
- SebAaltonen
description: "This is how you write a good x64 spinlock: Use two stage construct."
in_reply_to: ""
---
## Source
- URL: https://x.com/SebAaltonen/status/1125064645637738496
- Author: Sebastian Aaltonen (@SebAaltonen)
- Posted: 2019-05-05 15:48:08
## Thread
**1/** **@SebAaltonen** ^1125064645637738496
This is how you write a good x64 spinlock: Use two stage construct. Outer test is read. Multiple cores reading same cache line = no contention. Inner = exchange instead of CAS. Pause instruction in the loop body to save power and/or give all cycles to other logical core (SMT).
![](https://pbs.twimg.com/media/D50IVH0W0AALQ0y?format=jpg&name=orig)
**2/** **@SebAaltonen** ^1125065316650889217
Don’t use spinlock for waits. Use spinlock only to guard something that is guaranteed to return quickly. If you have an operation that is often fast but sometimes slow, use two stage spinlock with internal OS mutex.
**3/** **@SebAaltonen** ^1125067183476944896
Naive (bad) vs optimized (good) performance. See above post for code.
![](https://pbs.twimg.com/media/D50Ko4mXoAAR97L?format=jpg&name=orig)
Branches: [[archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two/2019-05-05-lectem-its-missing-exponential-backoff-for-mm-pause]], [[archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two/2019-05-05-AndrewJacksonZA-nice-code-up-above-also-https-x-com-sebaaltonen]]
+2
View File
@@ -9,7 +9,9 @@ tags:
- SebAaltonen
---
- [[archive/threads/SebAaltonen/2018-12-29-i-wish-i-was-as-productive-blogger-as-aras-p]]
- [[archive/threads/SebAaltonen/2019-01-01-now-that-people-have-already-said-highly]]
- [[archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two]]
- [[archive/threads/SebAaltonen/2022-11-22-ive-long-time-talked-about-killing-the-graphics]]
- [[archive/threads/SebAaltonen/2024-04-04-this-is-how-slow-code-feels-like]]
- [[archive/threads/SebAaltonen/2024-05-03-why-should-one-be-able-to-code-without]]