riot-ml / riot

An actor-model multi-core scheduler for OCaml 5 🐫
https://riot.ml
Other
548 stars 37 forks source link

Riot-friendly mutex #75

Open FayCarsons opened 5 months ago

FayCarsons commented 5 months ago

I volunteered for issue #46, but have been blocked on this and haven't heard from the person previously working on it, so I thought I'd pick it up :)

There were a few decisions I made that I'm not super sure of so definitely a draft! Feedback v much appreciated!

It seems to work, though I have observed the mutex process hanging if there are a lot of processes trying to get the lock. Not sure if that's specific to this or a larger issue w/ Riot.

The basic idea (which was partly inspired by the previous implementation) is:

Both the locking process and the mutex process monitor each other to prevent deadlocks that could be caused if one crashes while the other waits. The mutex process handles double locks/unlocks, other invalid messages, with a Failed (reason) message. Every function in the API, besides unsafe get and set, return a result so the locking thread can handle failures.

Some questions that came up while writing this: