Added windows threads.
Lots of tweaks to make msvc happy.