I am on Mac OSX, and sem_init is not supported (it was returning -1). I tried running the same code on a linux machine and it worked fine.
Moral of the story: I'm a goober and should check my return codes.