Fix deadlock in POSIX impelementation