Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Phaser ¶
type Phaser struct {
// contains filtered or unexported fields
}
Phaser is a synchronization primitive for coordinating multiple goroutines. I that combines the behavior of a latch, barrier, and phaser. Goroutines may register via Wait, be released one at a time via Signal or all at once via Broadcast. Ultimately, using Finish can ensure, that all wait is released, to ensure that all waiter is released.
Like sync.Mutex, a zero value Phaser is ready to use right away. If you’re using a sync.Mutex to protect shared resources, you can pass it as an optional argument to Phaser.Wait. This lets the mutex be released while waiting and automatically reacquired upon the end of waiting.
Example ¶
package main
import (
"go.llib.dev/testcase/pkg/synctest"
)
func main() {
var p synctest.Phaser
defer p.Finish()
go func() { p.Wait() }()
go func() { p.Wait() }()
go func() { p.Wait() }()
p.Broadcast() // wait no longer blocks
}
Click to show internal directories.
Click to hide internal directories.