Consider the following Go program allowing the parallel processing of two slices of an array. Here,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Answer rating: 100% (QA)
Heres the modified version of the program using a boolean channel f... View the full answer
Related Book For
Computer organization and architecture designing for performance
ISBN: 978-0136073734
8th edition
Authors: william stallings
Posted Date:
Students also viewed these programming questions
-
Ali Tours is comparing two capital structures to determine how to best finance its operations. The first option consists of all equity financing. The second option is based on a debt-equity ratio of...
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Gregorian Company has recently issued bonds that are convertible into stock at the bondholders request. The interest rate on the bonds is ridiculously low because it is expected that most holders...
-
What are the elements of Methods marketing mix?
-
Explain what happens to U.S. net exports and to U.S. aggregate demand as the dollar depreciates.
-
Sunshine State Fruit Company sells premium-quality oranges and other citrus fruits by mail-order. Protecting the fruit during shipping is important, so the company has designed and produces special...
-
Complete the following chart, indicating the comparative attributes of the typical trust and estate by answering yes/no or explaining the differences between the entities where appropriate. Attribute...
-
Schedule of Activity Costs Quality Control Activities Activity Cost Process audits $51,800 Training of machine operators 28,800 Processing returned products 19,100 Scrap processing (disposal) 25,300...
-
Question 1 Revisit Later 2. New companies, or companies with new products, often use very different advertising strategies than do experienced and trusted companies with established products. For...
-
Find the after-tax return to a corporation that buys a share of preferred stock at $35, sells it at year-end at $35, and receives a $4 year- end dividend. The firm is in the 30% tax bracket (Round...
-
Fortunately, the iron didn't hit a dolphin, but it quickly sinks to the bottom. Unfortunately, the meteorite has many sharp edges and she is worried the dolphins, curious creatures that they are,...
-
1) In the city of Tako, there is a veterinary clinic that offers medical care services for pets. The clinic cares for cats and dogs (the veterinary clinic has the capacity to care for a maximum of 60...
-
Chandler Packaged Treats (CPT) sells a specialty pet food to pet stores. CPT management prides itself on its scientific management methods. Applying those methods, the controller estimates the...
-
Imagine you are an analyst working at a financial consulting firm. Your organization has been hired by UBS to provide advice following a major legal and ethical crisis. You have been asked to draft...
-
Top-10 Origin AS by Prefix Growth Using the data from the cache files, calculate the percentage growth in advertised prefixes for each AS over the entire timespan represented by the snapshots by...
-
The domain of the variable in the expression x 3/x + 4 is________.
-
Form groups of four persons each. Each person should select one of the following four roles (if groups have between four and eight persons, two persons can play any of the roles in the exercise):...
-
Two years ago, a ship owned by a foreign company ran aground during a severe storm and sank at the entrance of a Canadian harbour. The vessel blocked the entrance to the harbour and spilled...
-
Direct labour is often accounted for at the gross wage rate, and the related benefit costs such as employer payroll taxes and employer contributions to health care plans are accounted for as part of...
Study smarter with the SolutionInn App