Show Bid Request
Producer-Consumer Problem
Bid Request Id: 16358
|
|
|
Posted by: |
ajd (4 ratings)
(Software buyer rating 10)
|
Non-action Ratio: |
Very Good - 0.00%
|
Buyer Security Verifications: |
Good
|
Approved on: |
May 14, 2002 10:18:51 PM EDT
|
Bidding Closes: |
May 18, 2002 10:22:27 PM EDT
|
Viewed (by coders): |
367 times
|
Deadline: |
5/20/2002
TIME EXPIRED
|
|
|
|
Description:
This program must be in pure ANSI C and compile on the Unix Platform
You are to create an ANSI C program that solves that Producer-Consumer problem with 8 producers, 12 consumers, and a buffer size of 5. Each producer and each consumer will be a separate thread, created by the main() function. The buffer will be a shared, globally declared queue implemented with a circular array of length 6, and will have two functions to modify it: enqueue() and dequeue() . Elements in the queue will be of type int . The signatures for these functions are given below.
void enqueue(int item); int dequeue();
Access to the buffer variables (array, indices, etc.) is sequentialized with a mutual exclusion semaphore, mutex . You will also have two other semaphores named empty and full . The semaphores needed are described below.
mutex Initially set to 1, this binary semaphore is used to control access to the shared data structure, the buffer. empty Initially set to 5, this counting semaphore controls the number of producers that can concurrently add items to the shared buffer. It is decremented when a producer adds an item and incremented when a consumer extracts an item. full Initially set to 0, this counting semaphore controls the number of consumers that can remove items from the shared buffer. It is incremented after a producer adds an item and is decremented when a consumer extracts an item. The following algorithms are to be used for the producer and the consumer threads. Please look carefully at the looping. Each producer/consumer will execute its corresponding algorithm, i.e., one producer thread will loop twelve times.
Producer:: Repeat 12 times Randomly generate an integer number /* Produce an item */ Print the generated integer /* show that it is "produced" */ wait on empty /* wait if no empty slots */ enqueue the integer in buffer /* mutex needed */ post on full /* allow another consumer */ Consumer:: Repeat 8 times wait on full /* wait if no items ready */ dequeue the integer from buffer /* mutex needed */ post on empty /* allow another producer */ Print the integer number /* show that it is "consumed" */
Deliverables: Complete and fully-functional working program(s) in executable form as well as complete source code of all work done.
Complete copyrights to all work purchased.
Platform:
Must be in pure ANSI C and compile on UNIX.
Must be 100% finished and received by buyer on:
May 20, 2002 EDT
Deadline legal notes: All times are expressed in the time zone of the site EDT (UT - 5). If the buyer omitted a time, then the deadline is 11:59:59 PM EDT on the indicated date.
Remember that contacting the other party outside of the site (by email, phone, etc.) on all business projects < $500 (before the buyer's money is escrowed) is a violation of both the software buyer and seller agreements.
We monitor all site activity for such violations and can instantly expel transgressers on the spot, so we thank you in advance for your cooperation.
If you notice a violation please help out the site and report it. Thanks for your help.
|
|
Bidding/Comments:
|
All monetary amounts on the site are in United States dollars.
Rent a Coder is a closed auction, so coders can only see their own bids and comments. Buyers can view every posting made on their bid requests. |
See all rejected bids (and all comments)
Name |
Bid Amount |
Date |
Coder Rating |
|
|
|
This bid was accepted by the buyer!
|
$25 (USD)
|
May 14, 2002 10:48:11 PM EDT
|
10
(Excellent)
|
|
|
I can complete this for you no problem. I have lots of experience in dealing with semaphores, threads, and I think I may have some code for this already. You will have it well before your due date, and you will get an A on this assignment. Check my ratings. |
|
|
|
|
|