Hacker News new | ask | show | jobs
by randbox 1614 days ago
How do you implement lockless atomic updates for multiple writers across multiple threads & processes without mmap?

With mmap it is straight forward for processes to open persistent arrays of atomics as a file, and use compare and exchange operations to prevent data races when multiple threads or processes update the same page without any file locks, advisory locks, or mutexes.

With manual read() and write() calls, the data may be overwritten by another writer before the update is committed.

2 comments

Normally, your IPC structures where you put lock-free data structures are mmaped in tmpfs, which is backed by RAM only, not files. A lot of the problems with mmap-ed files only show up when the file is larger than RAM (which is the case with databases). Files for IPC in tmpfs are usually small and don't have that problem.
Why do you need lockless atomic updates to a file-backed memory area? Genuinely curious.
Because it allows you to do lock free memory based interprocess communication, which can be extremely fast.
There is no need for file-backed memory to do that.
Sounds good, what is your solution and why didn't you explain it in your first reply?
What is my solution to what? To database I/O? I guess that's what the article is about...
I said "lock free memory based interprocess communication"

You said "There is no need for file-backed memory to do that."

If that is true, I want to know what you are talking about, so I'm just asking you to back up the claim you made.