async-lock icon indicating copy to clipboard operation
async-lock copied to clipboard

Support blocking and non-blocking operations on the same Mutex

Open joshtriplett opened this issue 2 years ago • 8 comments

Add lock_blocking and lock_arc_blocking methods to allow sharing the same lock between blocking and non-blocking code.

Introduce a helper macro to avoid duplicating the code of the acquire_slow method.

joshtriplett avatar Jul 02 '22 03:07 joshtriplett

Thanks @joshtriplett ! LGTM. Could see check why the mini test is failing?

zeenix avatar Jul 02 '22 16:07 zeenix

Thanks @joshtriplett ! LGTM. Could see check why the mini test is failing?

Ah nm. @taiki-e already fixed it: https://github.com/smol-rs/async-lock/pull/26 . Can you rebase?

zeenix avatar Jul 02 '22 16:07 zeenix

I'm a bit concerned about this. If this crate moves to a different backing implementation of synchronization, this may include a higher burden of porting.

notgull avatar Jul 03 '22 04:07 notgull

@zeenix Rebased.

@notgull Support for both blocking and non-blocking seems fairly fundamental to event-listener, and I think it's an important primitive for bridging between sync and async code. This is the kind of thing I'm hoping to see in the standard library in the future: not two completely independent lock types, but one lock type that works in both sync and async code.

joshtriplett avatar Jul 03 '22 05:07 joshtriplett

I see. I wonder if this could be done for async-channel, since that is also backed by event-listener.

notgull avatar Jul 03 '22 15:07 notgull

@notgull I very much hope so!

joshtriplett avatar Jul 06 '22 21:07 joshtriplett

@smol-rs/admins so any objections in merging this?

zeenix avatar Jul 06 '22 23:07 zeenix

I think a caveat like "calling this method on async code may cause deadlock" would be nice. Otherwise LGTM.

I wonder if this could be done for async-channel, since that is also backed by event-listener.

I would accept a PR that does this.

taiki-e avatar Jul 07 '22 12:07 taiki-e

What's needed for getting this in?

It would also be super useful to have this for RwLock.

dignifiedquire avatar Mar 01 '23 11:03 dignifiedquire

What's needed for getting this in?

It would also be super useful to have this for RwLock.

It would need a rebase, among other things. I've opened #39 as a replacement that also implements blocking ops for the other lock types.

notgull avatar Mar 02 '23 17:03 notgull

Closed by #56

notgull avatar Sep 23 '23 03:09 notgull