Question
In c++ code please Only Part B that says Write a C++ program called thread.cpp and make an executable with thread and a log file
In c++ code please
Only Part B that says "Write a C++ program called thread.cpp and make an executable with thread and a log file called thread.log for this part of your assignment." Information is below.
pseudocode to fit this lab
Producer function
{
Start by making the loop
Then creating the item
Then adding it to the buffer
End loop
Exit
}
Consumer function
Begins
Starts new loop
Updates min max and average
ends loop
exit
Main {
Definitions for variables, definitions and buffer size
creates producer
creates consumer
Joints both of them
Prints min max and average
returns
ends program}
Objective: Exercise writing Pseudocode for design of the program-code Experiments with Pthread processes Create, assign work, join (terminate) threads Create Programming Framework on Process Synchronizations for the next assignment. . Overview: Preamble: Create a subdirectory under your class directory named Threads to do all work on Lab3 assignment. The collecting parts of lab3 should be in Threads folder and not under any another directory. The general problem targets using Pthread processes to work collaboratively and concurrently on a shared resource. The program targets to develop and implement a Bonded-Buffer where several Producers make items to add into the buffer, while several Consumers try to receive these items from the buffer to consume. Producers & Consumers is a classic operating system problem demonstrating shared resources with multiple complication. Lab 3 covers Part 1 of the problem having only a single producer thread and a single consumer process thread. These two threads share one single buffer with a limited size of 10, and both exit when they have walked through the buffer. This assignment has multiple parts: Partl: Al: Pseudocode; Bl: Programming Code. Lab3 focuses on as the framework of the Producers & Consumers program to be launched in Lab4 as a follow-up assignment, with the detail synchronization between multi-processes. Part A1: Pseudocode: 5 Point: [Due date: Feb 151 Write a simple pseudocode for programming code of Bl to show the key steps of your programming development. Your pseudocode should clearly demonstrate following items: Creating Producer thread Creating Consumer threads Describe task for Producers [in separate function] Describe task for Consumers [in separate function] Initialization of the threads and RNG (using myID as its seed) Parents waits for thread terminations using join system call Parent prints the results . . When writing your pseudocode, think about how each line this pseudocode could be replaced with actual programming code. This is called program design. Part B1: 15 Points: Due date: Feb 23] [Read carefully this specification and ask questions on the details that are not clear] Write a C++ program called thread.cpp and make an executable with thread and a log file called thread.log for this part of your assignment. Detail Specification: There is a buffer with S=10 (the size of buffer is 10). The producer makes 10 items and add them to the buffer in order of 1, 2, 3 to 10 and stops. The consumer goes to the buffer 10 times and gets one-item-at-a- time to consume, but each time before accessing the buffer, it waits certain amount of time for the item to be produced. The buffer in this part, has a limited size of 10. When 10 items are produced or consumed, the program terminates. Consumer in this part (and for simplicity) can use a busy-loop for 10000 iterations. Inside the loop, there is a simple task like multiplying two numbers saving in third one; e.g. c=a*b. This busy loop forces the consumer to wait a bit! [It Part 2 of the problem, we will replace it with real waiting condition.] Create two Pthreads, one as producer and the second one as consumer. The producer generates a random number between 1 and1000 (simulating an item) and inserts it in the buffer. The consumer thread fetches these random numbers (one at a time) and considers them as products to consume. At the end of the program, the parent thread (the main program) reports the Min, Max, Avg of the items. Turned-in: Create a log file to record the behavior of your program in execution and print the output. Use "photo" or "script" to create the log-files. For example: $script thread.log At the start of the log, identify yourself first by pwd command, then follow the CMDs below: S pwd $ ls-0 S cat thread.cpp Sg++ thread.cpp -o thread -pthread $ ./thread [no need for argc & argy for this part] Colleted Files: Following files will be collected on each due date: thread.cpp & thread.log Notes Create a subdirectory Threads under your cs3080 folder and do all your work in this folder. To compile: g++ thread.cpp -o thread -pthread Run your program with different numbers While making logs, avoid using editor since it breaks your log with junks Pthread variables and functions useful for this Lab: pthread_attr_t a; // if needed pthread_t myID = pthread_self(); // returns calling thread's ID pthread_atti_init(&a); pthread_create (tidC[x], NULL, (void *) consumer, ...); pthread_create (tid[y], NULL, (void *) producer, ...); Objective: Exercise writing Pseudocode for design of the program-code Experiments with Pthread processes Create, assign work, join (terminate) threads Create Programming Framework on Process Synchronizations for the next assignment. . Overview: Preamble: Create a subdirectory under your class directory named Threads to do all work on Lab3 assignment. The collecting parts of lab3 should be in Threads folder and not under any another directory. The general problem targets using Pthread processes to work collaboratively and concurrently on a shared resource. The program targets to develop and implement a Bonded-Buffer where several Producers make items to add into the buffer, while several Consumers try to receive these items from the buffer to consume. Producers & Consumers is a classic operating system problem demonstrating shared resources with multiple complication. Lab 3 covers Part 1 of the problem having only a single producer thread and a single consumer process thread. These two threads share one single buffer with a limited size of 10, and both exit when they have walked through the buffer. This assignment has multiple parts: Partl: Al: Pseudocode; Bl: Programming Code. Lab3 focuses on as the framework of the Producers & Consumers program to be launched in Lab4 as a follow-up assignment, with the detail synchronization between multi-processes. Part A1: Pseudocode: 5 Point: [Due date: Feb 151 Write a simple pseudocode for programming code of Bl to show the key steps of your programming development. Your pseudocode should clearly demonstrate following items: Creating Producer thread Creating Consumer threads Describe task for Producers [in separate function] Describe task for Consumers [in separate function] Initialization of the threads and RNG (using myID as its seed) Parents waits for thread terminations using join system call Parent prints the results . . When writing your pseudocode, think about how each line this pseudocode could be replaced with actual programming code. This is called program design. Part B1: 15 Points: Due date: Feb 23] [Read carefully this specification and ask questions on the details that are not clear] Write a C++ program called thread.cpp and make an executable with thread and a log file called thread.log for this part of your assignment. Detail Specification: There is a buffer with S=10 (the size of buffer is 10). The producer makes 10 items and add them to the buffer in order of 1, 2, 3 to 10 and stops. The consumer goes to the buffer 10 times and gets one-item-at-a- time to consume, but each time before accessing the buffer, it waits certain amount of time for the item to be produced. The buffer in this part, has a limited size of 10. When 10 items are produced or consumed, the program terminates. Consumer in this part (and for simplicity) can use a busy-loop for 10000 iterations. Inside the loop, there is a simple task like multiplying two numbers saving in third one; e.g. c=a*b. This busy loop forces the consumer to wait a bit! [It Part 2 of the problem, we will replace it with real waiting condition.] Create two Pthreads, one as producer and the second one as consumer. The producer generates a random number between 1 and1000 (simulating an item) and inserts it in the buffer. The consumer thread fetches these random numbers (one at a time) and considers them as products to consume. At the end of the program, the parent thread (the main program) reports the Min, Max, Avg of the items. Turned-in: Create a log file to record the behavior of your program in execution and print the output. Use "photo" or "script" to create the log-files. For example: $script thread.log At the start of the log, identify yourself first by pwd command, then follow the CMDs below: S pwd $ ls-0 S cat thread.cpp Sg++ thread.cpp -o thread -pthread $ ./thread [no need for argc & argy for this part] Colleted Files: Following files will be collected on each due date: thread.cpp & thread.log Notes Create a subdirectory Threads under your cs3080 folder and do all your work in this folder. To compile: g++ thread.cpp -o thread -pthread Run your program with different numbers While making logs, avoid using editor since it breaks your log with junks Pthread variables and functions useful for this Lab: pthread_attr_t a; // if needed pthread_t myID = pthread_self(); // returns calling thread's ID pthread_atti_init(&a); pthread_create (tidC[x], NULL, (void *) consumer, ...); pthread_create (tid[y], NULL, (void *) producer, ...)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started