undefined reference to `sem_init'

C++
If you are on a linux system, you will need to compile and link with 
the -pthread flag to link the pthreads library.


$ gcc -pthread FileName.c
Source

Also in C++: