so I was looking over my next school assignment, and I'm baffled. I figured I would come to the experts for some direction. My knowledge on synchronization is severely lacking, and I didn't do so hot on the "mcopyfile" assignment it refers to. Terrible would probably be a good word for it. If I could get some direction on how to accomplish this problem, it would be much appreciated. Not looking for someone to do my assignment, just need someone to point me in the right direction. baby steps.
Based on the multi-threaded file copy tool (mcopyfile) you have created in Lab 2, now please use a worker pool (Producer-Consumer model) implementation that uses a fixed number of threads to handle the load (regardless how many files in the directory to copy). Your program should create 1 file copy producer thread and multiple file copy consumer threads (this number is taken from the command-line argument). The file copy producer thread will generate a list of (source and destination) file descriptors in a buffer structure with bounded size. Each time when the producer accesses the buffer it will write one (source, destination) file entry (per visit). And all file copy consumer threads will read from this buffer, execute the actual file copy task, and remove the corresponding file entry (each consumer will consume one entry each time). Both producer and consumer threads will write a message to standard output giving the file name and the completion status (e.g., for producer: “Completing putting file1 in the buffer”, for consumer: “Completing copying file1 to …”).
Assuming, you know how to spawn threads, let me break down the problem for you. There are following components:
Now as per the question, spawn a thread for producer and n threads for consumers. And this is what the threads do:
Producer thread
Consumer thread
I hope this helps.