Skip to Content
Hands-On Software Engineering with Golang
book

Hands-On Software Engineering with Golang

by Achilleas Anagnostopoulos
January 2020
Intermediate to advanced
640 pages
16h 56m
English
Packt Publishing
Content preview from Hands-On Software Engineering with Golang

Creating a distributed barrier for the graph execution steps

A barrier can be thought of as a rendezvous point for a set of processes. Once a process enters the barrier, it is prevented from making any progress until all other expected processes also enter the barrier.

In Go, we could model a barrier with the help of the sync.WaitGroup primitive, as follows:

func barrier(numWorkers int) {    var wg sync.WaitGroup    wg.Add(numWorkers)    for i := 0; i < numWorkers; i++ {        go func() {            wg.Done()            fmt.Printf("Entered the barrier; waiting for other goroutines to join")            wg.Wait()            fmt.Printf("Exited the barrier")        }()    }    wg.Wait()}

To guarantee that each worker executes the various stages of the graph state machine in lock-step with the other workers, we must ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Software Architecture with Golang

Hands-On Software Architecture with Golang

Jyotiswarup Raiturkar

Publisher Resources

ISBN: 9781838554491Supplemental Content