Fix for permission problem on windows
Fix bug on using critical section on windows