When you start working with thread or process you will probably need a way to coordinate them. One of this way is the use of semaphore, which allow you to coordinate several thread and regulate the access of shared memory.

Using C++, the are several libraries that provide semaphores. One of these, that is Posix standard, is the pthread library.
To us pthread, you have to include the phtread file in this way:
#include <pthreda.h>
But this is not enough. You also need to link the library, in this way:
g++ -lpthread file.cpp

In some system, anyway, linking with lpthread could still lead to other errors, some semaphore undefined reference, like this:

(.text+0x7e): undefined reference to `sem_open’
(.text+0xab): undefined reference to `sem_wait’
(.text+0x290): undefined reference to `sem_post’
(.text+0x2af): undefined reference to `sem_close’
(.text+0x2bb): undefined reference to `sem_unlink’
collect2: ld returned 1 exit status

This kind of error should be caused because using lpthread, your program will be linked with pthread libraries, that is not enough in some system.
If this happen, instead of lpthread, just try with pthread, like this
g++ -lpthread file.cpp

and everithing should be fine.