Thanks for your replies guys.

I solved it by basically going back and rewriting the thread more cleanly, so that its behavior to stochastic (i.e. user) input is more robust.

I don't know what the exact problem was, but the code looks prettier now and, it works both in debug and release!

-Kaushik