Question: Write a C/C++ program that uses the PTHREAD library to create 5 threads and MUTEXES to synchronize them. The program must do the following:
Write a C/C++ program that uses the PTHREAD library to create 5 threads and MUTEXES to synchronize them. The program must do the following: * The parant may initialize the mutexes, then call the 5 threads. Detach the threads once they are created. * Each thread will open its own command file (datal.in, data2.in, etc) for reading. The file format will be: R +/-N +/-N Note that there may be many +/-N lines W R indicates the start of a critical section the account balance from global storage. +/-N indicates a deposit (+N) or withdraw (-N) from the account. W indicates the end of the critical section where you will write the accout balance to global storage. At this point each thread must also display the text: Account balance after thread *thread_name_here* is $xxx NOTES: - - where you will acquire Start with a budget of 0 (zero). Each input file may be of different length and you may simply allow the thread to die at that point. Hence, the parent should NOT employ a pthread_join. REQUIREMENTS: The result of the single account should NOT contain any lost update. That is, the results should be the same as if a single thread processed all 5 input files on the single account (hint, for testing). However, you CANNOT force the threads into any serial execution. Once spawned they must be free from external influences (other than the mutexes). I suggest you include a sleep() function in each thread to make sure each thread runs long enough to get the random update behavior required. 1. Your program must run on the Linux Mint machines in Engineering. 2. Your full name must appear as a comment at the beginning of your program. 3. Your source code must be named hw4-yourname.c or hw4-yourname.cpp 4. Your source MUST compile using gcc or g++ in accordance with the extension. 5. Your program must only use mutex (s) for synchronization. No conditionals, no semaphores, no global variables. 6. Your program must use pthreads. Not threads. 7. Failure to follow 4 and 5 will result in -50% of the grade.
Step by Step Solution
3.37 Rating (156 Votes )
There are 3 Steps involved in it
Below is a C program that uses the PTHREAD library to create 5 threads and MUTEXES to synchronize them for the described task include include include ... View full answer
Get step-by-step solutions from verified subject matter experts
