[SOLVED] Threading Producer-Consumer C++

I don’t know how to handle this Computer Science question and need guidance.

Struggling to find relevant content or pressed for time? – Don’t worry, we have a team of professionals to help you on
[SOLVED] Threading Producer-Consumer C++
Get a 15% Discount on this Paper
Order Now

1. Consider a Producer-Consumer problem where M Producer threads run simultaneously to fill up a buffer. Then, exactly N Consumer threads will run simultaneously to take all the data out from the buffer. An example of such scenario is a file is striped into M different site. A downloader program starts M producer threads to get these chunks independently. Once M download threads (from a pool of threads) finish producing the items, the N Consumer threads simultaneously scan the data in their own way. Again, note that N out of many possible consumers succeed. Therefore, you cannot assume that only M producers and N consumers are presents. Look at the given program 1PNC.cpp(attached with semaphore.h which is needed to run with this) that works for 1 Producer and N Consumer threads. Be sure to run the program first to see how it behaves. You need to extend the program such that it works for all M producers instead of just 1. Add necessary semaphores to the program. However, you will lose points if you add unnecessary Semaphore. To keep things simple, declare the mutexes as semaphores as well. Then test your program to make sure that it is correct. In your submission directory, include a file called Q5.cpp that contains the correct program.

2. There are 3 sets of threads A, B, C. First 1 instance of A has to run, then 2 instances of B and then 1 instance of C, then the cycle repeats. This emulates a chain of producer-consumer relationship that we learned in class, but between multiple pairs of threads. Write code to run these set of threads.

Assumptions and Instructions: There are 100s of A, B, C threads trying to run. Write only the thread functions with proper wait and signal operation in terms of semaphores. You can use the necessary number of semaphores as long as you declare them in global and initialize them properly with correct values. The actual operations done by A, B and C does not really matter. Submit a separate C++ file called Q6.cpp that includes the solution.

3. Implement a Mutex using the atomic swap(variable, register) instruction in x86. Your mutex can use busy-spin. But assume that you cannot access a register directly other than using this swap instruction. (Note in some lecture, we solved this problem with direct access to the register allowed. For instance, you could simply write $register = 1. But you are not allowed to do that directly. You must do the following: int x = 1; swap (x, $reg) .

Calculate the price
Make an order in advance and get the best price
Pages (550 words)
*Price with a welcome 15% discount applied.
Pro tip: If you want to save more money and pay the lowest price, you need to set a more extended deadline.
We know how difficult it is to be a student these days. That's why our prices are one of the most affordable on the market, and there are no hidden fees.

Instead, we offer bonuses, discounts, and free services to make your experience outstanding.
Sign up, place your order, and leave the rest to our professional paper writers in less than 2 minutes.
step 1
Upload assignment instructions
Fill out the order form and provide paper details. You can even attach screenshots or add additional instructions later. If something is not clear or missing, the writer will contact you for clarification.
Get personalized services with MyCoursebay
One writer for all your papers
You can select one writer for all your papers. This option enhances the consistency in the quality of your assignments. Select your preferred writer from the list of writers who have handledf your previous assignments
Same paper from different writers
Are you ordering the same assignment for a friend? You can get the same paper from different writers. The goal is to produce 100% unique and original papers
Copy of sources used
Our homework writers will provide you with copies of sources used on your request. Just add the option when plaing your order
What our partners say about us
We appreciate every review and are always looking for ways to grow. See what other students think about our do my paper service.
Customer 452813, July 5th, 2022
They so amazing work!!
Customer 452707, January 29th, 2023
Customer 452813, June 25th, 2022
Customer 452813, July 5th, 2022
Customer 452813, June 20th, 2022
Strategic Management
Thanks for the help, really appreciate it
Customer 452821, June 26th, 2022
Business and administrative studies
Customer 452813, June 30th, 2022
Human Resources Management (HRM)
Thank you
Customer 452701, November 1st, 2022
Human Resources Management (HRM)
Thank you so much.
Customer 452701, October 11th, 2023
Great job
Customer 452813, July 27th, 2023
Social Work and Human Services
Great Work!
Customer 452587, October 13th, 2021
Customer 452813, June 25th, 2022
15% OFF your first order
Use a coupon FIRST15 and enjoy expert help with any task at the most affordable price.
Claim my 15% OFF Order in Chat

Get top-notch homework help now. 20% off first 10 orders!


Thank you for choosing MyCoursebay. Your presence is a motivation to us. All papers are written from scratch. Plagiarism is not tolerated. Order now for a 15% discount

Order Now