-
Notifications
You must be signed in to change notification settings - Fork 997
Implement sync
#881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement sync
#881
Conversation
0028eef to
fc2b5d5
Compare
fc2b5d5 to
a760304
Compare
a760304 to
3db2520
Compare
|
I have implemented most of |
|
Do you mean usage testing? If so then I can give this a try in the mqtt code we have that could really use a mutex. |
|
Yeah not sure how to best test this either. The happy flow should already be mostly tested in testdata/channel.go, and that is the only thing that's easy to test. It's hard to prove the non-existence of a concurrency bug. Some more real-world testing would definitely help build confidence, though! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some questions about the sync.Cond design. Maybe I misunderstood something but it doesn't seem sound right now. See my comments below.
The other commits look good to me (although I haven't tested them).
While adding some code to clear the Next field when popping from a task stack for safety reasons, the clear was placed outside of a nil pointer check. As a result, (*internal/task.Stack).Pop panicked when the Stack is empty.
|
CI had failed because of the issue described in #977, so I rebased on |
|
Looks good to me. However, some more testing would be good to have. @deadprogram you mentioned you might have some code with which you could test this? Also, you could add some tests to ./testdata/coroutines.go to check that at least the happy path works. Something along the lines of: // one goroutine
var l sync.Mutex
go unlocker()
l.Lock() // should suceed
println("mutex locked for the first time")
l.Lock() // should block until unlocked by the other goroutine
println("mutex locked for the second time")
// another goroutine
func unlocker() {
l.Unlock()
println("mutex unlocked...")
} |
|
@aykevl I added a test as requested. |
|
Thanks a lot! I have merged this without squasing because there were various commits that really were different features, although there were also some that might have been better squashed together with some other commit (such as the last one). I didn't want to lose that history. |
This is based on top of #828 and adds full support for the
syncpackage, implementing blocking by using theinternal/taskpackage.