Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1.txt (sample file, a number of files is provided by the user input) 2. Roster.txt Question: Anna, Nguyen, Thomas, Yun, Prateek, Favian, Abhinav, Ameena, Ryan,

1.txt (sample file, a number of files is provided by the user input)

image text in transcribed

2. Roster.txt

image text in transcribed

Question:

image text in transcribedimage text in transcribed

Anna, Nguyen, Thomas, Yun, Prateek, Favian, Abhinav, Ameena, Ryan, Parker, Omar, Charlotte, Ronnie, 20:36:34 20:37:05 20:37:12 20:38:23 20:50:18 20:50:33 20:51:44 20:53:08 20:53:14 20:53:21 20:53:47 20:54:03 20:54:04 20:54:22 20:57:07 From Nguyen : I notice the book and the lecture slides have dinos, what's up with that From Thomas : Dinosaurs make everything exciting.... From Yun : I like dinosaurs From Prateek : Are we going to choose are own groups or will they be random? From Favian : What are the presentations going to be about? From Nguyen : When will we choose our groups? From Abhinav : Yes Mam From Ameena : do well on coding assigments From Ryan: do well on both midterms From Parker : Understand the assignments From Omar : make sure, you and your group make a good presentation From Charlotte : go to office hours From Favian : Attend class and participate. Review plenty outside From Ronnie : Understand the assignments because the will be based on the exams? From Nguyen : Will the coding assignments be through Linux? Goals: 1. To evaluate process and disk scheduling algorithms 2.To experiment with threads and mutexes (see example code below). 3. To relate the threading, process synchronization, and deadlock concepts covered in class to a real-world problem. 4. To discover the challenges of debugging race conditions and deadlocks. Part 1 Objective Deterministic modeling is one type of analytic evaluation for scheduling algorithms. This method takes a particular predetermined workload and defines each process scheduling algorithm's performance for that workload. All processes arrive at same time 0, with different length of the CPU burst time. Implement a C++ program that determines which process scheduling algorithm would give the minimum average waiting time. Use the FCFS, SJF (non-preemptive), RR (quantum = 5 milliseconds), and Priority (with 3 priority levels) scheduling algorithms for this set of processes. Here's the format example: P1, 10,2 Create a user defined function that generates a random list that contains a unique PID along with a random BT, a random process priority number (1 - highest priority, 2 or 3). Then read the data from your text file into your variables and calculate an average wait time for each scheduling algorithm. Here's the example output: Average wait time for FCFS 28 Average wait time for Priority 26 Average wait time for SJF (non-preemptive) 13 Average wait time for RR 23 Thus, the SJF policy results the minimum average waiting time. Part II Implement the Part by using a multi-threaded application along with OOP style. In addition, each thread should be allowed to write the result of average wait times into the single text file - output.txt. The main thread should write the decision on the minimum average waiting time to the same text file, output.txt. Part III In this assignment, you will be writing a program that reads multiple text files parallel by using threads along with mutex and calculating the student's participation score. See attached Roster.txt 1.txt (sample file, a number of files is provided by the user input) Participation class (see skeleton below) The following ADT variable should be made available to all threads through a globally accessible ChatParticipation instance. Thus, all variables are allocated within a class and each thread should access to it by calling appropriate getter and setter functions. Implement required functionality for this ADT skeleton code. class Participation { private: int size; //size of the roster * names; // a pointer to a dynamic array with the names in the roster file int * participation Points; lla pointer to a dynamic array with the size of the roster. It stores participation points for each student. Example, Anna has 50 chats in all text files, thus participation Points[0]=50. int totalSum; lla variable to store a total number of all student messages in all chat files double * scores, l/a variable to store the outcomes, max score is 100. Assign a participation score to each student based on their participation points. Example, calculate an average for class participation points, suppose the class average is 45, and Anna has 50, thus scores [0]=100. Otherwise, the score needs to be adjusted /prorated. string public: Participation 0 { I/TODO: allocate dynamic arrays I/TODO: getter, setter, destructor methods } ChatParticipation; //global variable. All threads can access it. //This function header needs to stay the same. void *do_work(void *arg) /* TODO: This user-defined function is used by each thread accessing the unique data file (example: 1.txt 2.txt and so on). The result from this function is written into the private total sum variable and participation Points. Since the threads will need to modify the shared variables within the class, you are required to use the mutex variable for race condition prevention. *1 } The main program will ask for user for input for how many text files are available, then your program needs to populate the dynamic array of student names, listed in the Roster.txt The main program shall also create a dynamic number threads which preform calculation of participation Points and totalSum by using the same do_work function. The main thread needs to wait for all threads to finish and then calculate scores, and output the values i the following format: Student Name/Participation Points/Score. Part IV (for 4 students per group) Implement a multi-threaded linear search. The parent process shall load a file of strings into an array (or a vector), split the array inton sections, and then create n number of threads. Each child thread shall search one of the n sections of the array, for the specified string. If the thread does find the string, it records a number of occurrences. The main threads, meanwhile, executes the threads' join function. After all threads complete their search, then the main thread prints "string has been found by N threads, there are o occurrences for the sub-string" where N is a number of threads that found the string and O is a number of times that sub-string is present in the selected string. The program shall be ran using the following command line: ./multi-threaded You may create your test file words.txt with random words. Include a couple of test cases that your process has correct output. The textfile example: abc, xyz, abc, abc, abc, xyz, 999, oop. Command line: words.txt, abc, 4 The output example: The abc string has been found by 3 threads, there are 4 occurrences for the sub-string. Anna, Nguyen, Thomas, Yun, Prateek, Favian, Abhinav, Ameena, Ryan, Parker, Omar, Charlotte, Ronnie, 20:36:34 20:37:05 20:37:12 20:38:23 20:50:18 20:50:33 20:51:44 20:53:08 20:53:14 20:53:21 20:53:47 20:54:03 20:54:04 20:54:22 20:57:07 From Nguyen : I notice the book and the lecture slides have dinos, what's up with that From Thomas : Dinosaurs make everything exciting.... From Yun : I like dinosaurs From Prateek : Are we going to choose are own groups or will they be random? From Favian : What are the presentations going to be about? From Nguyen : When will we choose our groups? From Abhinav : Yes Mam From Ameena : do well on coding assigments From Ryan: do well on both midterms From Parker : Understand the assignments From Omar : make sure, you and your group make a good presentation From Charlotte : go to office hours From Favian : Attend class and participate. Review plenty outside From Ronnie : Understand the assignments because the will be based on the exams? From Nguyen : Will the coding assignments be through Linux? Goals: 1. To evaluate process and disk scheduling algorithms 2.To experiment with threads and mutexes (see example code below). 3. To relate the threading, process synchronization, and deadlock concepts covered in class to a real-world problem. 4. To discover the challenges of debugging race conditions and deadlocks. Part 1 Objective Deterministic modeling is one type of analytic evaluation for scheduling algorithms. This method takes a particular predetermined workload and defines each process scheduling algorithm's performance for that workload. All processes arrive at same time 0, with different length of the CPU burst time. Implement a C++ program that determines which process scheduling algorithm would give the minimum average waiting time. Use the FCFS, SJF (non-preemptive), RR (quantum = 5 milliseconds), and Priority (with 3 priority levels) scheduling algorithms for this set of processes. Here's the format example: P1, 10,2 Create a user defined function that generates a random list that contains a unique PID along with a random BT, a random process priority number (1 - highest priority, 2 or 3). Then read the data from your text file into your variables and calculate an average wait time for each scheduling algorithm. Here's the example output: Average wait time for FCFS 28 Average wait time for Priority 26 Average wait time for SJF (non-preemptive) 13 Average wait time for RR 23 Thus, the SJF policy results the minimum average waiting time. Part II Implement the Part by using a multi-threaded application along with OOP style. In addition, each thread should be allowed to write the result of average wait times into the single text file - output.txt. The main thread should write the decision on the minimum average waiting time to the same text file, output.txt. Part III In this assignment, you will be writing a program that reads multiple text files parallel by using threads along with mutex and calculating the student's participation score. See attached Roster.txt 1.txt (sample file, a number of files is provided by the user input) Participation class (see skeleton below) The following ADT variable should be made available to all threads through a globally accessible ChatParticipation instance. Thus, all variables are allocated within a class and each thread should access to it by calling appropriate getter and setter functions. Implement required functionality for this ADT skeleton code. class Participation { private: int size; //size of the roster * names; // a pointer to a dynamic array with the names in the roster file int * participation Points; lla pointer to a dynamic array with the size of the roster. It stores participation points for each student. Example, Anna has 50 chats in all text files, thus participation Points[0]=50. int totalSum; lla variable to store a total number of all student messages in all chat files double * scores, l/a variable to store the outcomes, max score is 100. Assign a participation score to each student based on their participation points. Example, calculate an average for class participation points, suppose the class average is 45, and Anna has 50, thus scores [0]=100. Otherwise, the score needs to be adjusted /prorated. string public: Participation 0 { I/TODO: allocate dynamic arrays I/TODO: getter, setter, destructor methods } ChatParticipation; //global variable. All threads can access it. //This function header needs to stay the same. void *do_work(void *arg) /* TODO: This user-defined function is used by each thread accessing the unique data file (example: 1.txt 2.txt and so on). The result from this function is written into the private total sum variable and participation Points. Since the threads will need to modify the shared variables within the class, you are required to use the mutex variable for race condition prevention. *1 } The main program will ask for user for input for how many text files are available, then your program needs to populate the dynamic array of student names, listed in the Roster.txt The main program shall also create a dynamic number threads which preform calculation of participation Points and totalSum by using the same do_work function. The main thread needs to wait for all threads to finish and then calculate scores, and output the values i the following format: Student Name/Participation Points/Score. Part IV (for 4 students per group) Implement a multi-threaded linear search. The parent process shall load a file of strings into an array (or a vector), split the array inton sections, and then create n number of threads. Each child thread shall search one of the n sections of the array, for the specified string. If the thread does find the string, it records a number of occurrences. The main threads, meanwhile, executes the threads' join function. After all threads complete their search, then the main thread prints "string has been found by N threads, there are o occurrences for the sub-string" where N is a number of threads that found the string and O is a number of times that sub-string is present in the selected string. The program shall be ran using the following command line: ./multi-threaded You may create your test file words.txt with random words. Include a couple of test cases that your process has correct output. The textfile example: abc, xyz, abc, abc, abc, xyz, 999, oop. Command line: words.txt, abc, 4 The output example: The abc string has been found by 3 threads, there are 4 occurrences for the sub-string

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Eric Redmond ,Jim Wilson

1st Edition

1934356921, 978-1934356920

More Books

Students also viewed these Databases questions

Question

A type of source that uses an operator to link keyboards is called

Answered: 1 week ago