Created
December 12, 2023 09:26
-
-
Save vizv/5bfa1b884987b4e8bb7e58bd63588abc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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