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

  Solution to the naur text-processing problem

Design and implement a solution to the Naur text-processing problem using the language specified by your instructor. Execute it against test data and record the number of faults you find and the cause of each fault

  Roman numeral equivalents of the decimal numbers

Write a program that prints a table of all the Roman numeral equivalents of the decimal numbers in the range 1 - 100.

  Design and implement a dynamic doubly linked list

Design and implement a dynamic doubly linked list - Allocate and de-allocate memory at runtime - Analyze a basic set of requirements for a problem

  The factorial of a positive integer n, denoted by n!

Write a program that computes the sequence of factorial values: 1! = 1, 2! = 2, 3! = 6, 4! = 24, 5! = 120, 6! = 720, ....

  Write me a function that finds the smallest item in an array

Write me a function that finds the smallest item in an ArrayBag (by reference) and returns true if the arrayBag is not empty and false otherwise.

  Write a program that prints minimax and maximin of a matrix

The optimal strategies are possible when these two values are equal. Write a program that prints the minimax and the maximin of a given matrix.

  Average of the bowler raw score

Display for each bowler the bowler name and the average of the bowler's raw score. Calcualte the current average and handicap for each bowler.

  Create a void function that takes as parameters

Create a void function that takes as parameters two integers, adds them, and prints them out to the command line.

  What are all of the values of the variables

Assume the calls are not accumulative; that is, they are always called with the initialized values of the variables, so their effects are not accumulative.

  Write c++ program to create a bar chart showing the average

Write a c++ program to create a bar chart showing the average monthly mean temperature for College Station from 2004 to 2013.

  Show the orders that produce different values

Provide an example in C++ of an expression whose value depends upon the evaluation order - Show the orders that produce different values and the values they produce.

  Write a program that uses a recursive method

Write a program that uses a recursive method to check whether a string is a palindrome and A palindrome is a string that reads the same both forward and backward.

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