Use cleanup handler in mac-specific semaphore implementation to allow its condition variable to be unlocked on thread cancellation