That's what semaphors are for ;)
Now my result is not 1 million, it is always exactly 2 million :S
using three threads, it is 3 million :S
Not sure what you mean by that? The total is 2 million instead of 1? Maybe think about how you are counting.
BTW: Thanks for the advice regarding the child stack, you were right, I used the same for all threads.
Strange thing is: If I use the same child stack for all threads, they count "together" to 1 million, as expected, but if they get their own child stacks, they all count to 1 million on their own :S