What is the correct way to write to a memory mapped file with no synchronization from multiple threads in Rust?
I need to create a 40+ GB file using multiple threads. The file is used as a giant vector of u64 values. Threads do not need any kind of synchronization -- each thread's output will be unique to that thread, but each thread does NOT get its own slice. Rather, the nature of the data ensures each thread will generate a set of unique positions in the file to write to. Simple example -- each thread writes to a position [ind / thread_count]
, where ind
goes to millions. For thread_count = 2
, one thread writes to odd positions, and the other to even.
I have used memmap2 - a new maintained fork of the memmap lib. The memmap2
seems to do everything I need for the access, but I do not know how to properly use it from multiple threads.