Closed xixixao closed 3 years ago
Hi, the original mutex example is made this way to highlight the "unlock on drop" behavior. The lock will be held for as long as guard
is in scope, which means the lock will be held for at least 1 second (because of the thread::sleep
). This should make it nice and easy to see each thread exchanging the lock back and forth when running the example. If this is not what happens when you run the example, then an issue should be filed.
This is the same behavior as regular std's MutexGuard.
I've updated the example so that you only have to run one instance of it and it spawns threads (instead of relying on users spawning two instances of the example).
Hopefully this clarifies things for you and future users
I think the example was clearer before (at least closer to what I'm using this library for).
If this is not what happens when you run the example, then an issue should be filed.
This is not what happens. I don't think Rust drops before the sleep.
I think you did fix it in the new code with the inner scope though.
Without releasing the lock the example doesn't give very interesting output.