Mutex from value in memory (mmap)

While implementing my blocking system using futexes, I wondered if I couldn't do something smarter.

Now, I directly use futexes to actually have a binary semaphore over a value in mmap. It's kind of cumbersome, but it works right now.
But, it is not as battle tested as a Mutex could be, since the latter IS using futexes underneath as well, but certainly more correctly than I do (corner cases.. the list is long).

My only issue is this:

let mutex = Mutex::new(0);

I would like something like

let mutex = Mutex::new(&from_value_in_mmap);

and mutex would directly apply the logic on the shared memory atomic u32, which is synchronizing the threads/processes.

Note: I just need to support Linux x86_64.

Is there a way to achieve this without needing to implement a full blow locking mechanism myself ?
Again, mine is working but I'm trying to converge the efforts.
Thanks :+1:

This crate is my answer.
it is an almost 100% match with my code.

I will converge on this crate.

Problem solved :+1:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.