Is it safe to use futex on AtomicU64?

⚓ Rust    📅 2025-09-22    👤 surdeus    👁️ 8      

surdeus

Warning

This post was published 39 days ago. The information described in this article may have changed.

The futex API supports only 32 bit atomics. There is also the futex2 API which technically allows for other sizes, but, unfortunately, 64 bit support is currently not implemented, so it does not help.

I would like to use futex with a 64 bit atomic. Let's assume that all control bits fit into 32 bits and the remaining 32 bits used for other purposes and may be mutated in parallel from other threads.

As much as I don't like it, but it looks to be the "recommended" approach:

Also note how you can use 64-bit atomic ops to do that all in user space,
without actually requiring 64-bit futex support - as long as the bits that
matter for waking (like "was there more than one pending writer") fit in
the one 32-bit word.

But I wonder whether it's compatible with the Rust memory model and the Intel's restriction on mixed-size atomic accesses.

2 posts - 2 participants

Read full topic

🏷️ Rust_feed