Use a few articles simple record C and C + + multithreaded programming basic things, each one program to record, Memo. These chapters are organized from one to the other, and depend on the dead dog.
Say it in the comments, Buddha-Lou.
#include <iostream>
#include <pthread.h>//header files are required and are compliant with POSIX standards to allow programs to be ported to many platforms
using namespace std;
#define NUM_THREADS 5
void* Say_hello (void* args)//The running function of the thread, must void*, say no to return universal pointer, input generic pointer
{
cout << " Hello ... "<< Endl;
}
int main ()
{
pthread_t tids[num_threads];//defines the ID variable for the thread, and multiple variables can declare an array to use for
(int i = 0; i < num_threads; ++i
{
int ret = pthread_create (&tids[i], NULL, Say_hello, NULL);//parameter in order: Created thread ID, thread parameter, call function name, passed function argument
if (ret!= 0)
{
cout << "Pthread_create error:error_code=" << ret << Endl;
}
}
Pthread_exit (NULL);//etc each thread exits, the process does not end, or the process is forced to end, the thread may not respond;
}
Compile command:
g++-lpthread-o test.out Test.cpp
Where calling the static library file pthread is necessary, and then run the test, Owen.
[cpp@node2 pthread]$, hello ... hello ... hello. ... hello .... [Cpp@node2 pthread]$