Skip to content

Instantly share code, notes, and snippets.

@vizv
Created December 12, 2023 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vizv/5bfa1b884987b4e8bb7e58bd63588abc to your computer and use it in GitHub Desktop.
Save vizv/5bfa1b884987b4e8bb7e58bd63588abc to your computer and use it in GitHub Desktop.
package main
import (
"log"
"math/rand"
"time"
)
type Barrier struct {
// TODO
}
func NewBarrier(n int) *Barrier {
// TODO
}
func (b *Barrier) Wait() {
// TODO
}
func main() {
b := NewBarrier(3)
for i := 0; i < 10; i++ {
go func(jobId int) {
sleepSecs := rand.Int31n(9)
log.Printf("%d: start (sleep %d seconds)\n", jobId, sleepSecs)
time.Sleep(time.Duration(sleepSecs+1) * time.Second)
log.Printf("%d: wait\n", jobId)
b.Wait()
log.Printf("%d: continue\n", jobId)
}(i)
}
time.Sleep(10 * time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment