Try:
gcc -pthread
instead of -lpthread . Of course, the difference is significant. The latter is linked to libpthread , the former is also linked to libpthread and a bunch of other things!
sem_wait is part of librt, so you can use gcc -lrt , but -pthread does this for you (and everything else!).
source share