Skip to content

Still misguiding/incomplete explanation of MutexGuard unlocking in ch20-02 [RE: #2108] #2330

Closed
rust-lang/rust
#80285
@Rotwang

Description

@Rotwang

Hi,
first of all I've read your book (also bought the dead tree version just to keep it in my personal library) and I must say that you did a great job explaining basics of rust. Rust makes me feel dumb every time I deal with it but your book made thinks smoother for me. Great job!

Regarding PR #2108 and issue #1871
Since I wasn't really satisfied with explanation given in the book I had to dig in a little bit more and found out this post (thread already linked in #1871):
https://users.rust-lang.org/t/drop-semantics-and-temporary-value-lifetimes-in-while-let/30903/15

According to explanation found in that thread the match and let semantics differ which is the reason behind the mutex being released in one case and not in another. It doesn't have anything to do with the type of a loop. I think it would be good to mention for the future readers that it comes down to differing semantics of match and let but the explanation of the difference falls outside of the scope of this book or something along those lines.

Here is a link to the part of the book in question: https://doc.rust-lang.org/book/ch20-02-multithreaded.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions