Made logging threaded

Fixes #200: made the logging threaded.
Fixes some of #1120: implemented thread_destroy for windows.