in c++ Modify “Producer and Consumer Problem” from the lecture note so that it can use all buffer
space, not “buffersize – 1” as in the lecture note. This
1. The user will run the program and will enter two numbers on the command line.
Those numbers will be used for buffersize and counter limit.
2. The main program will then create separate producer and consumer threads.
3. The Producer thread generates a random number through a random number
generator function, inserts it into the buffer, prints the number, and increment
counter.
4. The Consumer thread goes to the buffer, takes a number in the proper order, prints it
out, and increment counter.
5. After the counter reaches its limit, both threads should be terminated and returned to
the main.
6. Main program terminates.
Step by stepSolved in 2 steps
- JAVA PROGRAMMING You are required to create a main class to apply ExecuterService with SingleThreadExecuter. The variable i is integer number and MUST be input from the keyboard. Output should be like this: Please input i: 3 pool-1-thread-1: 1 pool-3-thread-1: 1 pool-3-thread-1: 2 pool-3-thread-1: 3 pool-2-thread-1: 1 pool-2-thread-1: 2 pool-2-thread-1: 3 pool-1-thread-1: 2 pool-1-thread-1: 3 Total = 9Below is the part of code.class Counter public class Counter { private int counter; public void increment(){ counter++; } public void decrement(){ counter--; } synchronized public void myIncrement(){ counter++; } synchronized public void myDecrement(){ counter--; } }arrow_forwardHello Can you please help me with this code because I am struggling how do to this, can you please help me this code has to be in C. Write a multithreaded program that calculates various statistical values for a list of numbers. This program will be passed a series of numbers on the command line and will then create three separate worker threads. One thread will determine the average of the numbers, the second will determine the maximum value, and the third will determine the minimum value. For example, suppose your program is passed the integers 90 81 78 95 79 72 85 The program will report The average value is 82 The minimum value is 72 The maximum value is 95 The variables representing the average, minimum, and maximum values will be stored globally. The worker threads will set these values, and the parent thread will output the values once the workers have exited. (We could obviously expand this program by creating additional threads that determine other statistical values, such as…arrow_forwardYou'll write a C++ program to demonstrate thread synchronization. Your main function should first create an empty file called *sync.txt*. Then it will create two separate threads: *Thread-A* and *Thread-B*. Both threads will open *sync.txt* and write to it simultaneously. *Thread-A* will write the numbers 0 through 9, a total of fifty-thousand times in nested `for` loops, then exit. In other words, print the numbers 0 through 9 over and over again, with each run on a separate line, for 50,000 lines. Here's an example of one such line: ```text 0 1 2 3 4 5 6 7 8 9 ``` Somewhat similarly, *Thread-B* will write the letters A through Z fifty-thousand times in nested `for` loops, then exit. In other words, print the letters A through Z over and over again, with each run on a separate line, for 50,000 lines. Here's an example of one such line: ```text A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ``` Do not write each line as one long string. You must write each character to the…arrow_forward
- Scenario: You have been tasked with building a URL file validator for a web crawler. A web crawler is an application that fetches a web page, extracts the URLs present in that page, and then recursively fetches new pages using the extracted URLs. The end goal of a web crawler is to collect text data, images, or other resources present in order to validate resource URLs or hyperlinks on a page. URL validators can be useful to validate if the extracted URL is a valid resource to fetch. In this scenario, you will build a URL validator that checks for supported protocols and file types.arrow_forwardPart II: Processes and Threads. Write a C program that will creates a child process. The child will ask the user to enter an integers x and then sends it to the parent via pipe. The parent should print your student's ID if x > 0 or your full student name if x 0 and 01998877 if x <= 0. Note: cach student should print his own id and name as they appear on the UMS. The inter-processes communication should be using pipes.arrow_forwardWrite java code to create a thread by (extending), theprogram create 3 thread that displaying “fatmah” and thenumber of thread that is running.Rewrite the above program by implementing the RunnableInterfacearrow_forward
- Exercise 1: Write a thread class TabPrinter that prints the elements of an array of integers (in one line) every 2 seconds 5 times. Use the way of extending the class thread. Write the main method which creates and starts three threads Printer which will print different arrays of integers. After that it prints "Main won’t wait. Main exits". Modify the above thread program so that you implement the interface Runnable. Make the main thread waiting till all other threads finish execution. ____________________________________________________________________________________________ Exercise 2: Write a thread class TextThread that prints a text every 1 second 10 times. Read the following main class. Try to guess what will be its output. class Test { public static void main(String s[]) throws Exception { TextThread x = new TextThread ("I am thread x"); TextThread y= new TextThread ("I am thread y"); System.out.println("I am Main thread"); } } Write it and execute it. Is the…arrow_forwardLab Activities: Exercise 1: 1) Write a thread class TabPrinter that prints the elements of an array of integers (in one line) every 2 seconds 5 times. Use the way of extending the class thread. Write the main method which creates and starts three threads Printer which will print different arrays of integers. After that it prints "Main won't wait. Main exits". 2) Modify the above thread program so that you implement the interface Runnable. Make the main thread waiting till all other threads finish execution.arrow_forwardSubject Name: Advanced Object-Oriented Programming 1. Complete the below given code (1) class NyThread Thread t: Runnable ( MyThread (String n, int pl t (2) (3) : / creates teh Thread t with nane n : // changen the priority to p Syster.out.printin ("Thread "+n+* created with priority "+p): t. (4) : // exexcute the thread t. I // The only abatarct aethed in Runnable public for (int 1=10: 1>=1: 1--) { Syaten.out.prántin ("Thread *t.getName ()+"\e i - "a) : (5) try { (6) :/ ma ke the Thead t eleep to 2 seconds } catch (Exception e) Syater.out.printin ("Exception in Child"): System.out.printin ("Thread "+t. getName ()+" 1s Exiting"): public statie void main (Stringt) arga) { MyThread t1, 12; ti - new MyThread ("R1", 7): t2 = new MyThread ("R1", 3): try ( :// 2 atatements to aake the Threads ti a v2 exit at same time (8) ) catoh (Exception e) ( Syster.out.printin("Exception in main"): System.out.printin ("Thread Main is Exiting"): 1. 2. 3. 4. 6. 7. 8. 5.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education