Question: package main import ( fmt math / rand os strconv sync time ) func main ( ) {
package main
import
fmt
"mathrand
os
"strconv"
sync
"time"
func main
rand.SeedtimeNowUnixNano
if lenosArgs
fmtPrintlnPlease provide an integer argument."
return
num, err : strconv.AtoiosArgsconvert to int
if err nil
fmtPrintlnInvalid input type."
return
unbuffered : makechan intunbuffered channel
var wait syncWaitGroup
wait.Addbegin incrementing the counter
go producer&wait, unbuffered, num
go consumerunbuffered
wait.Wait
func producerwait syncWaitGroup, out chan int, num int
defer wait.Done
for x :; x num; x
value : rand.Intnnum
fmtPrintfProduced: v
value
out value
closeout
func consumerin chan int
for v : range in
fmtPrintfConsumed:v
v
Write the following code using a bufffered channel instead of an unbuffrered channel in GOLANG
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
