Objective: Practicing synchronization, mutex, and condition variables, multithreaded programming with Pthreads (POSIX threads).
In this project, you will write a multithreaded program that will implement a version of the producer-consumer problem using mutex and condition variables of the Pthreads library. There will be N threads that will act as producers (producer 0, 1, 2, 3, N-1). The minimum value of N is 1, and the maximum value is 10. There will be one thread that will act as the consumer. Between a producer and consumer, there will be a bounded buffer of size M (set to 100 by default items). Hence, there will be a total of N buffers. The minimum value of M is 10, and the maximum value is 1000. Each producer will send a sequence of student records (items) of the type shown below through its buffer. The consumer will retrieve those records and will sort them as they arrive and write them to an output file in sorted order, one record per line.
struct student {
int sid;
char firstname[64];
char lastname[64];
double cgpa;
};
You will consider synchronization. Access to a buffer should be done in a mutually exclusive manner. If all buffers are empty, the consumer will go to sleep. If a buffer is full, the respective producer will sleep.
Name your program as pcsync. It will take the following parameters:
pcsync <buffersize> <infilename> <outputfilename>
<infilename> is the name of the input file that will contain student records in the following format:
<producerid> <sid> <firstname> <lastname> <cgpa>
<producerid> is a value between 0 and N-1.
For example:
0 2015008910 Ali Dag 3.45
3 2015008920 Veli Irmak 3.33
2 2015017893 Hakan Cay 3.60