首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

pthread线程小结和使用

2013-01-27 
pthread线程总结和使用#include iostream#include pthread.husing namespace stdvoid * thread_proc(

pthread线程总结和使用

#include <iostream>#include <pthread.h>using namespace std;void * thread_proc(void*){        for(int i = 0; i < 10; ++i){                cout << "123" << endl;                sleep(1);        }        return 0;}int main(){     //1     pthread_t thread_id;     thread_id = pthread_self(); //        if (pthread_equal(thread_id, pthread_self())){                cout << "Equal!" << endl;        }else {                cout << "Not queal!" << endl;        }        //2        pthread_t thread_new;        int rc = pthread_create(&thread_new, 0, thread_proc, 0);        if (rc != 0){                cout << "pthread_create error!" << endl;                return -1;        }        pthread_join(thread_new, 0);        pthread_destory(thread_new);        return 0;}

热点排行