Fixed some issues with POSIX semaphore.