Question: In this assignment, write a Go program to simulate the producer / consumer processes, as described in section 3 . 5 of the Operating System

In this assignment, write a Go program to simulate the producer/consumer processes, as described in section 3.5 of the Operating System Concepts book:
simulate a producer and a consumer, each as a goroutine:
the producer produces a given number of random integers (in a given range), and sends each to the consumer via an unbuffered channel (unidirectional or bidirectional)
the producer goroutine outputs each number before it sends it
the consumer receives each integer from the producer and consumes it
the consumer goroutine outputs each number after it receives it
modify your program from part 1 so that a buffered channel of a given size is used
Sample Runs
Part 1(the command line argument determines both the number of integers and the range of integers)
$ go run main.go 10
Produced 2
Consumed 2
Produced 6
Produced 5
Consumed 6
Consumed 5
Produced 9
Produced 4
Consumed 9
Consumed 4
Produced 2
Produced 0
Consumed 2
Consumed 0
Produced 5
Produced 0
Consumed 5
Consumed 0
Produced 7
Part 2(a buffered channel of size 3 is used)
$ go run main.go 10
Produced 1
Produced 4
Produced 0
Produced 1
Consumed 1
Consumed 4
Consumed 0
Consumed 1
Produced 4
Produced 7
Produced 0
Produced 8
Produced 9
Consumed 4
Consumed 7
Consumed 0
Consumed 8
Consumed 9
Produced 9 Write for GOLANG

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!