Question: The following program demonstrates a parallel loop in Go. However, this program should wait for the go routines to terminate before ending. Remove the Sleep

 The following program demonstrates a parallel loop in Go. However, this The following program demonstrates a parallel loop in Go. However, this program should wait for the go routines to terminate before ending. Remove the Sleep statement and replace it by a proper synchronization. package main import "fmt" import "time" func main() { x := []int{3, 1, 4, 1, 5, 9, 2, 6} var y [8]int // boucle parallele for i, v := range x { go func (i int, v int) { y[i]= calcul(v) }(i,v) // appel a la goroutine } // ajouter synchronisation time.Sleep(1*time.Second) fmt.Println(y) } func calcul(v int) (int) { return 2*v*v*v+v*v }

Question 1 (1 point) The following program demonstrates a parallel loop in Go. However, this program should wait for the go routines to terminate before ending. Remove the Sleep statement and replace it by a proper synchronization. package main import "fmt" import "time" func main() { X:= := []int(3, 1, 4, 1, 5, 8, 2, 6) vary [8]int // boucle parallele for i, v:= range xl go func (i int, v int) { v[i] = calcul(v) (i,v) // appel a la goroutine 1 // ajouter synchronisation time.Sleep(1*time. Second) fmt.Println(y) ] func calcully int) (int) { return 2*v*v*v+v*v }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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

Students Have Also Explored These Related Databases Questions!