20.8k views
0 votes
This assignment will introduce you to interprocess synchronization mechanisms in UNIX using named POSIX semaphores, pthread mutex semaphores, and pthread condition variables.

Problem:
For this assignment, you will modify your solution for programming assignment 1 to comply with the restrictions explained below.
Your multithreaded Incremental entropy algorithm implementation must execute the following steps:
o Read the input from STDIN (the Moodle server will implement input redirection to send the information from a file to STDIN). The input has the following format:
A 2 B 4 C 3 A 7
B 3 A 3 C 3 A 1 B 1 C 1
 Each line represents the scheduling information from a CPU.
o Create n POSIX threads (where n is the number of input strings). Each child thread executes the following tasks:
 Receives the input information from the main thread.
 Uses the given incremental entropy algorithm to calculate the entropy of the CPU at each scheduling instant.
 Prints the scheduling information of the assigned CPU using the output messages from the example below.
Given the previous input, the expected output is: ________

User MattTriano
by
7.5k points

1 Answer

6 votes

Final answer:

The correct approach requires implementing concurrency controls, such as POSIX semaphores and pthread primitives, to a multithreaded process that reads input from STDIN and computes entropy for each CPU scheduling interval.

Step-by-step explanation:

The correct answer is that you would need to implement variable modifications to a program that uses multithreaded processes, employing POSIX semaphores, pthread mutex semaphores, and pthread condition variables for synchronization between threads. The main thread would have to read the input from STDIN, where the input is formatted as pairs of a character and an integer value representing CPU scheduling information. Each line of input would be handled by a separate child thread that calculates the entropy for each CPU at given intervals.

Considering the asynchronous nature of the threads, pthread mutex semaphores may be used to protect shared data from concurrent access, ensuring data consistency. To avoid busy-waiting and reduce CPU time consumption, you could also apply pthread condition variables that wait for a specific condition to occur before a thread proceeds.

Without the actual incremental entropy algorithm and the complete program, it is impossible to provide a precise expected output. However, the output should present the entropy of the CPU at each scheduling instant as calculated by the child threads.

User Shree Singhi
by
8.6k points