> The problem is that threads go to sleep while still holding a lock. Yes, this was my mistake. Thanks! But anyway after moving sleep to the right place all still hangs with 6+ characters.
> Well, the real problem is that afaik there is no guarantee that this code > will ever finish, > because the scheduler is not required to ever wake the > right thread when a bunch of other threads are still waiting. I think this shouldn't be the case. Even when we have 100+ threads an OS thread scheduler gives the chance to be executed to each one. So even without any sleep entire work should definitely finish but CPU load would be 100%. P.S. I just tried to test without sleep: all finishes for 1-5 characters - 100% CPU load. It seems there's some other reason of hang up.