I wrote a simple program solving the Readers-Writers problem using semaphores. It runs perfectly on Linux os, but when I run it on my Mac osX I get unexpected results and I
Check the error return on the sem_init calls; I bet you'll find the OS X version returning a "Function not implemented" error.
This is because unnamed POSIX semaphores are not implemented on OS X. You need to use named semaphores, or pthread mutex/condition variables.