Skip to content
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

Introduce HOFs that wrap functions to run with a locked mutex #716

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

yawaramin
Copy link

Introduce wrappers that can turn any function f : a -> b into a new function that runs with a wrapped mutex. a can even be a mutable value that can then be modified only while the mutex is held.

Fix #336

@talex5
Copy link
Collaborator

talex5 commented Mar 23, 2024

This seems not quite the same as your #336 proposal - in fact, it seems incompatible with that idea (of storing the protected resource inside the mutex). Here it's passed as an argument instead.

This "wrap" is effectively the same as "use", except using the alternative API style of taking an argument for the function.

e.g. it allows writing wrap_ro m foo x instead of use_ro m (fun () -> foo x).

The problem usually with this form is that it's really easy to mess it up when you have more than one argument:

wrap_ro m foo x y

Tthis takes m while creating the partially-applied foo x, but then runs foo x y without the lock, which was probably not what was wanted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mutex API ergonomics
2 participants