Conversation
a8af420 to
01aa45d
Compare
| @@ -5,17 +5,19 @@ import "sync" | |||
| // baton is a channel-based mutex. This allows for using it as part of a select | |||
| // statement. | |||
| type baton struct { | |||
There was a problem hiding this comment.
Does this have a test suite which picked this up?
There was a problem hiding this comment.
To answer your question as written: no, there's no existing test suite that picked it up. I don't mind adding a test though.
zhming0
left a comment
There was a problem hiding this comment.
The new implementation looks sound so ✅ .
But I have a question about how the deadlock would occur.
| // Something holds the baton, so record that this actor is | ||
| // waiting for the baton. | ||
| b.acquire[by] = ch | ||
| return ch |
There was a problem hiding this comment.
Is this deadlock? or race condition instead.
If release happened in between return ch and <-ch, then I think the worst case is that multiple parties consider themselves as holder at the same time.
But I don't see how deadlock is happening.
There was a problem hiding this comment.
Assume two actors "a" and "b", one runs <-b.Acquire("a") and the other b.Release("b"). Release scans all entries in the b.acquire map to find any that are waiting on the channel. If the Release in "b" happens after Acquire returns (it must at least wait for the mutex), but before the channel is being waited on by "a", then the scan finds no channel being waited on, so assigns the holder to "" and has cleared the map as it goes.
01aa45d to
acdb0e8
Compare
acdb0e8 to
17d38d0
Compare
Description
Fixes a concurrency design problem in
baton.go- revert to using something much closer to @zhming0 's design (#3722).Currently, the following program deadlocks:
The reason is that
Releasecan occur in betweenAcquirereturning the channel, and the channel receive.Releasesees no other actor waiting for the channel, so drops the baton.Context
It came to me in a dream.
Changes
Revert the design to be closer to #3722
Testing
go test ./...). Buildkite employees may check this if the pipeline has run automatically.go tool gofumpt -extra -w .)Disclosures / Credits
I did not use AI tools at all