Why `MutexGuard` impls `Sync` but not `Send`?

MutexGuard impls both Sync and !Send.
I guess it is because poisoning is not allowed to happen on thread which is not the creator of the guard. Please correct me if I'm wrong, and if it's true, please tell me why this is not allowed. Thanks.

I recommend reading all of this:

The part about your specific question:

For a more realistic example, it turns out that MutexGuard is not Send, since for the definition of MutexGuard to be maximally portable, it needs to support the POSIX API of pthreads, which states that a lock can only be released from within the thread where it was created.

7 Likes

Thanks, I got it.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.