Question: Consider the following Go program allowing the parallel processing of two slices of an array. Here, synchronization is achieved with a WaitGroup. Rewrite the

Consider the following Go program allowing the parallel processing of two slices

Consider the following Go program allowing the parallel processing of two slices of an array. Here, synchronization is achieved with a WaitGroup. Rewrite the program is performing, this time, a synchronization with a boolean channel (chan bool). So you can no longer use the sync package: package main import ( > "fmt" "sync" func main() { } var wg sync.WaitGroup x = []int(3, 1, 4, 1, 5, 9, 2, 6} var y [8]int wg.Add(2) // number of goroutines to synchronize // parallel loop in 2 slices go calcul2(x[:4], y[:4], &wg) go calcul2(x[4:], y[4:], &wg) wg.wait() // waiting for the 2 goroutines fmt.Println(y) func calcul2(in (Jint, out []int, wg sync. WaitGroup) { for i, v := range in { out[i] = 2*v*v* + *v } wg.Done() // signals that the goroutine is finished.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres the modified version of the program using a boolean channel f... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Document Format (2 attachments)

PDF file Icon

663e546659d76_958004.pdf

180 KBs PDF File

Word file Icon

663e546659d76_958004.docx

120 KBs Word File

Students Have Also Explored These Related Programming Questions!