Skip to content

Comments on Message receive and wait channel misleading #4

Open
@WhisperingChaos

Description

@WhisperingChaos

Certain comments in the sequencing pattern imply Joe's goroutine will generate the first received Message struct followed by Ann's:

msg1 := <-c // Waiting on someone (Joe) to talk
fmt.Println(msg1.str)
msg2 := <-c // Waiting on someone (Ann) to talk
fmt.Println(msg2.str)
msg1.wait <- true // Joe can run again
msg2.wait <- true // Ann can run again

However, the code doesn't explicitly define a Happens Before dependency to ensure this ordering. Therefore, it's possible that Ann's Message struct will precede Joe's resulting in the variable msg1 containing Ann's message, not Joe's as suggested by the comments.

If a strict Round-robin ordering is desired, the following implementation delivers the same outcome while eliminating the wait abstraction and its associated code.

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