From: Tassilo Horn Date: 2004-10-09T02:04:54+09:00 Subject: Re: Problems with my first multithreaded Rupy programm "SER" writes: > A couple of things. Perfect. I'm willing to learn. > 1) Create the Waiter last. He's got the lock on the mutex, so none of > the other threads can enter their synchronized sections, so they can't > wait. They're simply blocking while waiting to enter the protected > section. It doesn't matter that the waiter is sleep()ing, because he > still has the lock. If you create the waiter last, then everybody else > has a chance to enter a synchronized section and wait (releasing the > lock) before the waiter does his thing. Ah, I understand. > 2) Don't use Thread.stop. It isn't doing what I think you think it is > doing. I was quite sure it's not doing what I wanted it to do but had no better idea how to do what I want it to do. ;-) > 3) Create another CV just for the waiter, so you can send signals > directly to him And that is the solution for 2) which I didn't realize. > 4) Wrap your "whiles" in the synchronized sections, not the other way > around. For one thing, entering synchronized sections are costly; you > want to do it as rarely as you can. For another, when you wait(), you > release the lock, allowing others to get at the lock, so it is OK to > put the while inside the synchronized section. Ok. > 5) If I was going to clean up the code for you, I'd recommend doing > something like this: Oh, thanks. I hope I'll be disciplinated enough to first implementing your tips on my own before reading you code... Much thanks for your great help. But _one_ posting would have been enough! ;-) Regards, Tassilo