First, download the Windows version of Pthread
Currently the latest version is:pthreads-w32-2-9-1-release.zip.
Second, unzip the pthread to the specified directory
The directory I chose is: When E:\DEV-CPP\Pthread is complete, the directory will have three more folders: Pre-built.2,pthreads.2,queueuserapcex.
iii. Configuring dev-c++ compilation Options
1) Click "Tools" → "Compile Options" → "contents" → "C + + Include files", browse to the Pthread directory you just unzipped, select E:\DEV-CPP\Pthread\Pre-built.2\include, Add.
2) Click "Tools" → "Compile Options" → "contents" → "libraries", browse to the Pthread directory you just unzipped, select E:\DEV-CPP\Pthread\Pre-built.2\lib, Add.
iv. If "undefined reference to ' Pthread_create" error occurs, add the-lpthread parameter to the compiler option
Five, finally attach a simple multithreaded example
#include <iostream>#include<pthread.h>#include<cstdio>using namespacestd; void* HJZGG (void*Arg) { while(1) {cout<<"Hello, everyone!. I am hjzgg!"<<Endl; GetChar (); } returnNULL;} intMainintArgsChar*argv[]) {pthread_t tid; Pthread_create (&tid, NULL, HJZGG, NULL); while(1);//The main thread does not end prematurely return 0; }
Using dev-c++ to develop pthread.h-based multithreaded threads under windows