Write a program that will take a list of filenames on the command-line. If the list is empty, print an error message and exit. As in Lab 9, assign a Posix thread to each filename and have it count the number of newlines in its file. But in this lab have the threads coordinate to report a single global sum of how many newlines there are in total in all files. Your solution should use a mutex to protect threads adding their local count to the global count. Also, use a condition variable to have the main thread wait for the global count to be complete, then have the main thread print the global count.
Be sure to consider the case where the thread's open of a file fails. The thread should report an error, but the program should not deadlock.
Please turn-off any debugging code before you submit your lab.
Comments and questions should be directed to hatcher@unh.edu