Java Semaphore north south que?

You've only modeled the children, not the actual roundabout. I doubt each child needs its own thread, unless that's been mandated.

You've only modeled the children, not the actual roundabout. I doubt each child needs its own thread, unless that's been mandated. What seems a more useful approach is to make three threads, one for each queue, and one for the roundabout.

The roundabout is the worker thread and the child queues are the producer threads. Your roundabout thread would have a circular buffer of children, each with a 'time to play' decided randomly when they enter the roundabout. The thread would periodically check the 'time to play' of each child and when any of them expire it would eject them randomly into the north or south queue and raise a semaphore that a space is open.

The two queue threads would each wait on the semaphore and whenever it went up, the first one to acquire it would put its child into the roundabout structure with a randomly chosen 'time to play'. Alternatively you could have the roundabout thread eject people into the east and west playgrounds at random and have the queuing threads responsible for emptying them. You need to ensure that each shared collection (the circular buffer and the actual list of children in each of the queue threads) is properly handled in terms of synchronization.

You will only need two classes, the roundabout thread and the queue thread, but there will be two instances of the queue thread, one for north and one for south.

More than likely, they want an application that will simply run forever. The app as you've described it has no output, so the design of the program is the point. I expect that the grading for something like this will be executing it for a few hours to ensure that it a) doens't lose any children along the way and b) doesn't enter a non-viable state like a deadlock condition.

– Jherico Dec 15 '09 at 21:44 why don't you take a shot at it and if you encounter a problem you can't figure out, come back and ask a more specific question. – Jherico Dec 16 '09 at 7:32 roundabout class is the problem..... – Mult Dec 16 '09 at 23:58.

If this is all you have, it's not enough for me to help you, it'd feel like i'm doing the whole thing.

Your roundabout doesn't seem to exist at all, unless that's how you intend the homework to be. But i'd add some semaphores and a mutex to ensure they don't get on roundabout when it's ocupied by somone else. – user233220 Dec 16 '09 at 20:02 cool, i'll look into it later tonight.

But in the mean time ask other coders on the board, they're pretty helpfull, make sure your question is visible to most ppl. Will get back to you soon. – user233220 Dec 16 '09 at 20:47 Thanks a lot greenman for all your help... I really appreciate it... please keep in touch after you have got to some conclusion....i'll be waiting... I am still in doubt whether its right or wrong... but thanks again... – Mult Dec 16 '09 at 20:52 .. Did you look for what sort of output would come out?

Or what have you got? – Mult Dec 16 '09 at 23:52 I am not able to make the roundabout class...any help there? – Mult Dec 16 '09 at 23:58.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions