Downside I: Write a whole Go program whose primary perform spawns a fan of n goroutines and synchronizes them, with out busy ready, in order that they cooperatively alternate printing ping pong to plain error, the place n is given as a command-line argument. Every line should be printed to plain error by a distinct goroutine, and no goroutine should printmore than as soon as. The goroutines needn’t print within the order through which they’re created. As an illustration, 
$ go run PingPongFan. go 10
1 ping // printed by goroutine 9
2 pong // printed by goroutine 5
three ping // printed by goroutine three
four pong // printed by goroutine four
5 ping // printed by goroutine 2
6 pong // printed by goroutine 6
7 ping // printed by goroutine 7
eight pong // printed by goroutine eight
9 ping // printed by goroutine 1
10 pong // printed by goroutine 10
$
Your program should not comprise any race circumstances. Don’t give greater than 25 traces of code. 
Downside II: Write a whole Go program whose primary perform spawns a series of n goroutines and synchronizes them, with out busy ready, in order that they cooperatively alternate printing ping pong to plain error, the place n is given as a command-line argument. Every line should be printed to plain error by a distinct goroutine, and no goroutine should print greater than as soon as. As an illustration, 
$ go run PingPongChain. go 10 1 ping // printed by goroutine 1 2 pong // printed by goroutine 2 three ping // printed by goroutine three four pong // printed by goroutine four 5 ping // printed by goroutine 5 6 pong // printed by goroutine 6 7 ping // printed by goroutine 7 eight pong // printed by goroutine eight 
  
9 ping // printed by goroutine 9
10 pong // printed by goroutine 10
$
Your program should not comprise any race circumstances. Don’t give greater than 25 traces of code. 

Published by
Write
View all posts