News for hackers. Stuff that matters.
Re:Things Unix can do atomically (2010) by ridiculous_fish on Monday May 30, 2016 @09:26PM (#11804075)
Here's one that's not super well-known: writes to a pipe are atomic as long as the write size is <= PIPE_BUF, which is at least 512 bytes (on Linux it's a full 4k). So pipes can be used as a naïve message queue: ensure each message is under the limit in size, and they will not be split.

Anyone know if there's a similar guarantee for files?

Re:Things Unix can do atomically (2010) by bluetomcat on Tuesday May 31, 2016 @03:31AM (#11805226)
The PIPE_BUF POSIX requirement is about guaranteeing that when multiple processes write less than PIPE_BUF to the same pipe, the reader will not see its input intermingled from different processes. It is often wrongly interpreted as "a single write() of less than PIPE_BUF will be retrieved via a single read() on the other side".
Re:Things Unix can do atomically (2010) by colmmacc on Monday May 30, 2016 @09:32PM (#11804089)
They won't be split, bit one thing to watch out for is that they can be coalesced.
Re:Things Unix can do atomically (2010) by brobinson on Tuesday May 31, 2016 @12:40AM (#11804601)
I read a while back that this PIPE_BUF restriction also applies to multiple writers appending a file.
Re:Things Unix can do atomically (2010) by adrianratnapala on Tuesday May 31, 2016 @12:44AM (#11804617)
I think Linux goes out of its ways to make writes <= 512 bytes atomic. Helpful for writing log files. But I don't think this is a true guarantee in any standardised sense.
Re:Things Unix can do atomically (2010) by the8472 on Tuesday May 31, 2016 @04:15AM (#11805359)
Opening with O_APPEND you get atomic appends if they're <= PIPE_BUF.

And the list already mentions atomic memory operations. Those also apply to memory-mapped files.