Fixed threading issue on windows