Zulip Chat Archive

Stream: lean4

Topic: read/write lock


Adrien Champion (Mar 02 2023 at 10:29):

I know Lean has IO.Mutex, but does it have anything resembling a read/write lock?

Adrien Champion (Mar 02 2023 at 10:30):

If not, how feasible/easy would it be to implement a version of it?

James Gallicchio (Mar 02 2023 at 21:36):

If we're just shooting for something like https://doc.rust-lang.org/std/sync/struct.RwLock.html that relies on the underlying OS implementation, seems doable

Adrien Champion (Mar 03 2023 at 00:46):

Coming from Rust, that's exactly what I had in mind :grinning:

Adrien Champion (Mar 03 2023 at 01:02):

So if I understand this correctly there would be some C code / OS hook involved

Adrien Champion (Mar 03 2023 at 01:02):

My understanding is that in this case, that should be in core since std4 does not feature such low-level code

Adrien Champion (Mar 03 2023 at 01:02):

And Mutex is already there

Adrien Champion (Mar 03 2023 at 01:03):

Is that correct? @Gabriel Ebner

Adrien Champion (Mar 03 2023 at 01:04):

I would be interested in taking a shot at contributing RwLock, especially since there's already code for Mutex so even I might be able to do it

Gabriel Ebner (Mar 03 2023 at 01:36):

I think it's pretty straightforward to build a (non-reentrant) read-write mutex using regular mutexes and condition variables (which we both have).

Adrien Champion (Mar 03 2023 at 01:52):

Interesting, and would you say it'd be better putting that in std if it's pure Lean?

Gabriel Ebner (Mar 03 2023 at 02:11):

I have no idea if Mario wants to have extra mutex stuff in std, but there's no need for such an implementation to be in core.

Mario Carneiro (Mar 03 2023 at 02:25):

If there is a good API for it and core doesn't want it I don't see any issue with putting it in std


Last updated: Dec 20 2023 at 11:08 UTC