Hmm, I guess this will be "fun" to debug. Couple more questions:

  1. you mentioned that it happens after using cout, what happens if you don't use it?
  2. How many threads are you starting and from where? All from main thread? Or each thread starts another thread?