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

  Write a program that will read in 4 test scores

Write a program that will read in a list of numbers and double each number. Your program should work for any number of lines of data.

  Implement a function called findmax

Implement a function called findMax that finds the maximum value in a 2¬dimensional array.

  Accepts a pointer to a c-string as an argument

Write a function that accepts a pointer to a C-string as an argument and capitalizes the fist character of each sentence in the string. For instance, if the string argument is "hello

  Examine the differences between a linear and augmented line

"Developing a Website" Please respond to the following: Examine the differences between a linear and augmented linear structure. Examine the differences between hierarchical and linear structures. Explain why a coherent structure is necessary. Provid..

  Create a map and store social security numbers by names

Create a map and store social security numbers by names. Iterate through your container and retrieve all names. Seach for an individual name and print the ssn

  Calculation the distance and time printed on the screen

After each calculation the distance and time printed on the screen and accumulated to the sum of the total distance and sum of the total time. The current destination should be saved as the old postion for the next calculation

  Write a switch-case programming for calculation

How to use C++ to write a switch-case programming for calculation? Test the program for a wide range of possible inputs including division by zero and square root of negative values.

  Program that asks the user to enter a number from 1 to 50

Print the statement "Programming is fun" the number of times entered by the user using a for loop.

  Prepare a main function

Write a function that converts an input of some integer number of nickels into outputs of integer numbers of dollars, quarters, and nickels.

  Write a program to calculate cars mileage

If you are using VisualStudio 2005, you should include time.h. The call to srand should use the time rather than a number entered by the user and looks like this: srand( static_cast(time( NULL )) ).

  Determine a mixed strategy for terry

If he studies biology and there is a quiz in it, he gains ten points but there is no gain if there is no quiz. Determine a mixed strategy for Terry, and the expected payoff.

  Find the minimum value in an array

Write a recursive function recursive Minimum that takes an integer array and the array size as arguments and returns the smallest element of the array.

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