Project 3, producer/consumer

48 views
Skip to first unread message

scar...@gmail.com

unread,
Mar 21, 2018, 1:23:47 AM3/21/18
to asu-cse-430
Ok, so a producer consumer problem runs producer so long as there is room left (<N) 'on the shelf' and consumes so long as there is a product to consume.

So our previous programs produced a queue of threads and switched between the elements in the queue continuously.  Since the program executed sequentially, the various threads cannot execute out of order or create run conditions as they could in real life.

So, to create producer consumer building on what we have, is the Queue we have the 'shelf'?  Do we set a maximum for it?  (say 1)
Then we create 2 producer threads, and 2 consumer threads, and add them if there is room left, remove them if there is one running?  To accurately test the use of semaphores, we'd need to add more than the queue maximum and then the P() method would not add to the RunQ, but instead add the new thread to a SemQ.  V() would remove a thread from the RunQ, and release any that are in the SemQ?

Is this what we're trying to implement?  Or am I completely off base?

Thanks,
Brian G
Message has been deleted

Partha Dasgupta

unread,
Mar 21, 2018, 4:18:08 PM3/21/18
to asu-c...@googlegroups.com
Not quite sure I am interpreting the question correcly. The shelf is the buffer (array of items). You do not add/remove threads, you add remove items from the shelf (array). The prod/cons threads execute using semaphores.... the only queues are semaphore queues, there is no explicit thread queues.

Partha Dasgupta,
ASU/CIDSE/Computer Science & Eng. 
EMail: par...@asu.edu
http://cactus.eas.asu.edu/partha

--
You received this message because you are subscribed to the Google Groups "asu-cse-430" group.
To unsubscribe from this group and stop receiving emails from it, send an email to asu-cse-430+unsubscribe@googlegroups.com.
To post to this group, send email to asu-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/asu-cse-430.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages