-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Waiters lock-free #382
Comments
Instead of making it lock-free, I added a separate Cells module for lock-free users. Promise, Condition, Semaphore and 0-capacity Streams now use that. The remaining uses are:
|
Looking at the -Mutex.use_rw ~protect:false mutex thunk
+Mutex.use_rw mutex thunk -Mutex.use_rw ~protect:true mutex thunk
+Mutex.use_rw mutex (Cancel.protect thunk) I guess the intention with the API is to force the user to think about cancellation. The names, For example, the common pattern using Mutex.lock mutex;
Fun.protect ~finally:(fun () -> Mutex.unlock mutex) begin fun () ->
(* modify or examine state, never enter scheduler *)
while (* some condition *) do
(* await unlocks the mutex, so state needs to be consistent at this point *)
Condition.await condition mutex
done
(* modify or examine state, never enter scheduler *)
end should be safe as long as the As background information for others, I've been looking into the synchronization structures of Eio to see how one could implement them using compositional lock-free algorithms (using kcas). |
Yes, it's trying to get users to think about two things:
I'm not super happy about the names either, especially as it makes it sound like a RW lock. |
Waiters currently needs a mutex to protect the list of waiting fibers. This prevents us from using it in signal handlers or GC finalizers (see #374). We can't use
Lf_queue
here because we need to support cancellation (removing waiters from the middle of the queue).https://arxiv.org/pdf/2111.12682.pdf ("A formally-verified framework for fair synchronization in Kotlin coroutines") could be a good solution, and will probably be faster too.
The text was updated successfully, but these errors were encountered: