Write a complete go program whose main function spawns chain

Assignment Help C/C++ Programming
Reference no: EM131912298

Assignment

Problem I: Write a complete Go program whose main function spawns a fan of n goroutines and synchronizes them, without busy waiting, so that they cooperatively alternate printing ping pong to standard error, where n is given as a command-line argument. Each line must be printed to standard error by a different goroutine, and no goroutine must printmore than once. The goroutines need not print in the order in which they are created. For instance,

$ go run PingPongFan. go 10
1 ping // printed by goroutine 9
2 pong // printed by goroutine 5
3 ping // printed by goroutine 3
4 pong // printed by goroutine 4
5 ping // printed by goroutine 2
6 pong // printed by goroutine 6
7 ping // printed by goroutine 7
8 pong // printed by goroutine 8
9 ping // printed by goroutine 1
10 pong // printed by goroutine 10

Your program must not contain any race conditions. Do not give more than 25 lines of code.

Problem II: Write a complete Go program whose main function spawns a chain of n goroutines and synchronizes them, without busy waiting, so that they cooperatively alternate printing ping pong to standard error, where n is given as a command-line argument. Each line must be printed to standard error by a different goroutine, and no goroutine must print more than once. For instance,

$ go run PingPongChain. go 10 1 ping // printed by goroutine 1 2 pong // printed by goroutine 2 3 ping // printed by goroutine 3 4 pong // printed by goroutine 4 5 ping // printed by goroutine 5 6 pong // printed by goroutine 6 7 ping // printed by goroutine 7 8 pong // printed by goroutine 8

9 ping // printed by goroutine 9
10 pong // printed by goroutine 10

Your program must not contain any race conditions. Do not give more than 25 lines of code.

Reference no: EM131912298

Questions Cloud

How does the media portray women vs men leaders : Discussion Post topic: How does the media portray women vs. men leaders? What could the media do to help increase the representation of women and minorities.
Can you identify the ideology of the terrorists in that case : Think of one terrorist attack that has occurred in recent history. Can you identify the ideology of the terrorists in that case?
How does baby compare to the norms of development : Describe this baby and his/her behavior in several paragraphs, including age and appearance. Describe everything the baby did while you were there.
Amount of proceeds from the sale will sam get to keep : How much of the total amount of proceeds from the sale will Sam get to keep?
Write a complete go program whose main function spawns chain : Write a complete Go program whose main function spawns a chain of n goroutines and synchronizes them, without busy waiting.
How the media actually benefited the terror organization : Select one past incident where the media has served as a force multiplier for terror groups, & explain how the media actually benefited the terror organization.
What should be the service rate : What should be the service rate to make sure that the chance of having no more than 2 customers in the system is 90%?
Dividend paid by the company to barry will he get to keep : Suppose the Gingridge pays a dividend per share of $2.25. How much of the total dividend paid by the company to Barry will he get to keep?
Uses the dividends from giggle to meet certain expenditures : Shawn uses the dividends from Giggle to meet certain expenditures, and is disappointed to learn that Giggle will forego a dividend this year.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd