Warning
This post was published 60 days ago. The information described in this article may have changed.
I have an array of atomics, let's say [AtomicU64; 512]
. During the first stage I fill this buffer using atomic operations and during the second stage the buffer stays read-only (there is a proper memory synchronization between the stages).
Now, at the start of the first stage I also want to write the data to disk. The obvious solution would be to copy data to a scratch buffer suing atomic operations and write data from this buffer, but it's obviously inefficient. Would it be sound to cast the original buffer to [u8; 4096]
and pass it to the write syscall despite the fact that other threads may read data from it using atomic operations?
In my opinion, it should be sound. But there is this unfortunate restriction from the Intel manual:
Software should access semaphores (shared memory used for signalling between
multiple processors) using identical addresses and operand lengths. For example,
if one processor accesses a semaphore using a word access, other processors
should not access the semaphore using a byte access
In my understanding, this restriction applies only to mutating atomic operations ("semaphores", "signalling between multiple processors"), so it's not applicable to my case.
cc @RalfJung
4 posts - 4 participants
🏷️ rust_feed