I picked up the following demo off the web from https://computing.llnl.gov/tutorials/pthreads/
#include
#include
#define NU
Acutally, it gives several examples of compile commands used for pthreads codes are listed in the table below, if you continue reading the following tutorial:
https://computing.llnl.gov/tutorials/pthreads/#Compiling
Running from the Linux terminal, what worked for me was compiling using the following command (suppose the c file I want to compile is called test.c):
gcc -o test test.c -pthread
Hope it helps somebody!
Both answers to this question so far are incorrect.
For Linux the correct command is:
gcc -pthread -o term term.c
In general, libraries should follow sources and objects on command line, and -lpthread
is not an "option", it's a library specification. On a system with only libpthread.a
installed,
gcc -lpthread ...
will fail to link.
In Anjuta, go to the Build menu, then Configure Project. In the Configure Options box, add:
LDFLAGS='-lpthread'
Hope it'll help somebody too...
check man page and you will get.
Compile and link with -pthread.
SYNOPSIS
#include <pthread.h>
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg);
Compile and link with -pthread.
....
I believe the proper way of adding pthread
in CMake
is with the following
find_package (Threads REQUIRED)
target_link_libraries(helloworld
${CMAKE_THREAD_LIBS_INIT}
)