[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.
How it works
Receive a 100% original paper that will pass Turnitin from a top essay writing service
step 1
Upload your 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.
Pro service tips
How to get the most out of your experience with MyCoursebay
One writer throughout the entire course
If you like the writer, you can hire them again. Just copy & paste their ID on the order form ("Preferred Writer's ID" field). This way, your vocabulary will be uniform, and the writer will be aware of your needs.
The same paper from different writers
You can order essay or any other work from two different writers to choose the best one or give another version to a friend. This can be done through the add-on "Same paper from another writer."
Copy of sources used by the writer
Our college essay writers work with ScienceDirect and other databases. They can send you articles or materials used in PDF or through screenshots. Just tick the "Copy of sources" field on the order form.
See why 20k+ students have chosen us as their sole writing assistance provider
Check out the latest reviews and opinions submitted by real customers worldwide and make an informed decision.
Always on time and a life saver for sure!!!!!!!!!!!!
Customer 452453, October 22nd, 2021
I requested two pages and only have one page and the second pages is references.
Customer 452475, August 22nd, 2022
excellent service! Not a beat missed!
Customer 452453, October 17th, 2021
Web programming
Customer 452715, September 16th, 2022
Thank you MyCoursebay team for your support. With your help I got an A for my past courses
Customer 452635, May 7th, 2022
Social Work and Human Services
Thank You! Great Work!
Customer 452587, September 14th, 2021
Customer 452813, June 26th, 2022
Great paper!
Customer 452707, July 1st, 2022
Paid for the paper to be completed 5 days prior than the day I received the paper.
Customer 452693, July 13th, 2022
ENG 099
Excellent Paper. The only 100 in the class.
Customer 452775, July 19th, 2022
Thank you for the great services
Customer 452635, April 24th, 2022
Great writer (Proske). I highly recommend
Customer 452531, July 10th, 2021
Customer reviews in total
Current satisfaction rate
3 pages
Average paper length
Customers referred by a friend
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

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