Make semaphore usage portable, using named semaphores on Mac. Fixes #943