Semaphore implementation: untested on unix