Working MAC OS X port.
Compatibility layer for semaphore handling.