Converted everything to boost::thread so we can compile it on Windows with MingW in Win32 threading mode.

This allows us to use TCMalloc.
Changed code that causes a compiler crash.