Results 1 to 2 of 2
- 03-08-2014, 04:43 PM #1Senior Member
- Join Date
- Jul 2012
- Rep Power
Concurrent processing - 6 threads sharing resources - wait() and notify()
I am writing a program based on the dining philosophers problem using just wait() and notify() and, as I have never done concurrent processing before, I want to make sure that I am heading in the right direction with what I am doing.
If you don't know, the dining philosophers problem states that there are 6 people around a table with 6 pieces of cutlery in between them (1 to the left and 1 to the right of each person). Two people cannot use the same piece at the same time and both pieces are required for the person to eat. I have to ensure that each person gets a chance to eat (has both pieces at the same time) and each person gets a chance to think (has none). We can't have a person going too long without a piece as they will starve.
Back to my program:
Do I need to make pairs of the people either side of a piece of cutlery, then as one person picks up this piece, the wait() method is called on the other thread (person) to halt it until the other person has finished eating where he will then call notify() to wake up the other thread and let that person pick up the cutlery?
I haven't done any concurrent processing, as I said, so don't know how I link these two threads together. I have seen some mention of "synchronise" on tutorials I have attempted, is that what I need. Also, I am struggling to see a way of doing this for 6 threads (people) simultaneously (Do I just do lots of overlapping synchronisation pairs?).
Can somebody point me in the right direction on how to start or on some good tutorials (Not the orcale one, I have gone through this) that will be helpful for this situation?
- 03-08-2014, 06:27 PM #2Senior Member
- Join Date
- Feb 2014
- Rep Power
Re: Concurrent processing - 6 threads sharing resources - wait() and notify()
If you use "wait notify tutorial" as a search term in google/bing, you'll find loads of relevant pages, e.g.,
- Thinking in Java 13: Concurrency - Wait and notify
- Using wait() and notify() in Java to implement a latch
- Java Thread wait, notify and notifyAll Example
- Java notify() and wait() examples
There are also YouTube tutorials on this, e.g., Advanced Java: Multi-threading Part 8 - Wait and Notify - YouTube
- By mariki in forum Threads and SynchronizationReplies: 6Last Post: 07-20-2012, 09:37 PM
- By Cropcircles in forum Threads and SynchronizationReplies: 4Last Post: 03-25-2012, 10:44 PM
- By jomypgeorge in forum New To JavaReplies: 4Last Post: 02-15-2011, 09:58 AM
- By mityay in forum Threads and SynchronizationReplies: 3Last Post: 01-06-2011, 05:24 PM
- By Mkaveli in forum Threads and SynchronizationReplies: 2Last Post: 03-30-2010, 11:58 AM