Skip to content

Chapter 16.3: is a microphone at a panel a good analogy? #4530

@NeatNit

Description

@NeatNit
  • I have searched open and closed issues and pull requests for duplicates, using these search terms:
    • microphone
  • I have checked the latest main branch to see if this has already been fixed, in this file:
    • src/ch16-03-shared-state.md

URL to the section(s) of the book with this problem: https://doc.rust-lang.org/book/ch16-03-shared-state.html

The introduction of this chapter uses this analogy:

For a real-world metaphor for a mutex, imagine a panel discussion at a conference with only one microphone. Before a panelist can speak, they have to ask or signal that they want to use the microphone. When they get the microphone, they can talk for as long as they want to and then hand the microphone to the next panelist who requests to speak. If a panelist forgets to hand the microphone off when they’re finished with it, no one else is able to speak. If management of the shared microphone goes wrong, the panel won’t work as planned!

In my opinion this is a pretty bad analogy. Here are some reasons why:

  • In real world conferences where there's a panel discussion, each panelist would usually have their own microphone. And they can often speak at the same time, for better or worse.
  • If a panelist forgets to hand off the microphone, the other panelists can easily remind them to do so or request it, which isn't a realistic possibility with a mutex.
  • Two panelists absolutely can share a microphone, and it's quite common to place a stationary microphone between two panelists to reduce the number of microphones on stage.

Some options I thought of for a different analogy:

An old-school phone booth: only one person can practically use it at any one time, and while they're using it the door is closed preventing others from entering. When they are finished using it, they have no choice but to leave the booth, freeing it up for other people.

Questions after a presentation: steering closer to the conference metaphor, we could discuss the questions at the end, which I think is a far more accurate analogy. When a presentation ends, audience members have a chance to ask questions, and they raise their hand to indicate they want to do so. A staff member selects one, gives them a wireless microphone, and they ask their question and receive an answer. Afterwards the staff member takes the microphone away and selects a new audience member.

The audience members are threads, the microphone is the shared resource, and the staff member handing off the microphone is the mutex.

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