如何在DevC++中使用pthread库?

sza*_*man 7 pthreads windows-vista

我从pthread下载了pthread包.我现在该怎么做才能在DevC++中使用它?

Mah*_*iya 8

  1. 下载pthreads devpak 下载
  2. 在Dev C++中安装它
  3. 在Dev C++中创建新项目
  4. 之后转到项目菜单 - >项目选项 - >在其中选择"参数选项卡"
  5. 选择"添加库或对象"选项
  6. 从Dev c ++的安装目录中选择"libpthreadGC2.a"文件它将在LIB目录中.
  7. 按确定
  8. 现在测试以下示例代码准备好运行..

示例代码:

#include <iostream>
#include <pthread.h>
using namespace std;
void * fun_thread1(void *data)
{
    for(int i=0;i<100;i++)
    { 
        cout<<endl<<"In Thread 1"<<endl;
    }     
}
void * fun_thread2(void *data)
{
    for(int i=0;i<100;i++)
    { 
        cout<<endl<<"In Thread 2"<<endl;
    }     
}
int main(int argc, char *argv[])
{
    int status;
    // creating thread objects
    pthread_t thrd_1;
    pthread_t thrd_2;
    // create thread
    pthread_create(&thrd_1,NULL,fun_thread1,(void *)0);
    pthread_create(&thrd_2,NULL,fun_thread2,(void *)0);    
    pthread_join(thrd_1, (void **)&status);
    pthread_join(thrd_2, (void **)&status);
    system("PAUSE");
    return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)