unfortunetly dispatch_semaphore_* for OS X is not fork safe, try to implement semaphores using conditional variables