Stream: general

Topic: Unix Mutex `Send`


Lee Mracek (May 12 2019 at 06:30, on Zulip):

I'm not clear on why https://github.com/rust-lang/rust/blob/master/src/libstd/sys/unix/mutex.rs is Send. My understanding is that an ownership transfer to a different thread involves a move and pthread mutexes cannot be moved.

Florian Gilcher (May 12 2019 at 11:21, on Zulip):

It moves the pointer to the mutex, not the mutex itself.

Lee Mracek (May 12 2019 at 22:11, on Zulip):

Not in the unix implementation? It's just an UnsafeCell wrapping a pthread_mutex_t which is typically just a struct.

I expect ::std::sync::Mutex to be sync and send since it's in a Box, but the internal implementation isn't.

RalfJ (May 13 2019 at 10:27, on Zulip):

the internal Mutex is Send but not movable... it's a bit weird, but e.g. &mut Mutex is fine to Send.

RalfJ (May 13 2019 at 10:28, on Zulip):

making it non-Send wouldnt help with the issues around moving it

RalfJ (May 13 2019 at 10:28, on Zulip):

but anyway all that will be moot once https://github.com/rust-lang/rust/pull/56410 lands

Lee Mracek (May 13 2019 at 14:35, on Zulip):

Ooo yup hadn't seen that PR

Last update: Nov 22 2019 at 00:00UTC