Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8745957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:07:11+00:00 2026-06-13T12:07:11+00:00

so I was looking over my next school assignment, and I’m baffled. I figured

  • 0

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 …”).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:07:12+00:00Added an answer on June 13, 2026 at 12:07 pm

    Assuming, you know how to spawn threads, let me break down the problem for you. There are following components:

    1. Producer. It generates Tasks for the Consumers based on the source directory input parameter.
    2. Task. A task is information for Consumer to execute its copy task. Namely a tuple of source file descriptor and destination file descriptor.
    3. Queue. It is the central piece of communication between Producer and Consumer. Producers writes Tasks to Queue and Consumer consumes it.
    4. Consumer. You have a pool of actual workers that take Task as input and executes copy operation.

    Now as per the question, spawn a thread for producer and n threads for consumers. And this is what the threads do:

    • Producer thread

      1. For list of files in the source directory:
        1. Task <- (Source file path, destination file path)
        2. Acquire lock on Queue
        3. Write Task to queue
        4. Release lock on Queue
        5. Acquire lock on stdout
        6. Write to stdout
        7. Release lock on stdout
    • Consumer thread

      1. While True:
        1. If size of queue == 0:
          1. Sleep for some time
        2. Else:
          1. Acquire lock on Queue
          2. Dequeue a Task
          3. Release lock on Queue
          4. Execute copy operation
          5. Acquire lock on stdout
          6. Write to stdout
          7. Release lock on stdout

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was looking over the code for qunit. My question is why would you
I have been looking all over the internet and i found some good guides
I was looking over what's coming with the next WinRM and PowerShell 3 and
Looking over the magento 1.5 schema I cannot seem to figure out how a
I am looking over csipsimple app - uses sip calls, registers. I also found
I have been looking over the internet for a while about this, but it
I have been looking over this code for the past hour, I cant see
I have a little / weird behaviour here and Im looking over internet and
I'm pretty new to Ruby. I've tried looking over the online documentation, but I
I have been looking all over for this. I have two seperate prpt files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.