标签:
1. Pthreads例子
POSIX线程(POSIX threads),简称Pthreads,它是线程的POSIX标准。该标准定义了创建和操纵线程的一整套API。在类Unix操作系统(Unix、Linux、Mac OS X等)中使用Pthreads作为操作系统的线程。Windows操作系统也有其移植版pthreads-win32。Pthreads定义了一套C语言的类型、函数与常量,它以pthread.h头文件和一个线程库实现。举个例子,如下所示:
1 #include <pthread.h> 2 #include <iostream> 3 using namespace std; 4 5 void* tprocess1(void* args) { 6 while(1) { 7 cout << "tprocess1" << endl; 8 } 9 return NULL; 10 } 11 12 void* tprocess2(void* args){ 13 while(1){ 14 cout << "tprocess2" << endl; 15 } 16 return NULL; 17 } 18 19 int main(){ 20 pthread_t t1; 21 pthread_t t2; 22 pthread_create(&t1, NULL, tprocess1, NULL); 23 pthread_create(&t2, NULL, tprocess2, NULL); 24 pthread_join(t1, NULL); 25 return 0; 26 }
说明:g++ TestPthreads.cpp -o TestPthreads -lpthread
2. Nsight Eclipse Edition开发Pthreads应用程序
主要是配置Cross G++ Linker中的Libraries。如下所示:
参考文献:
[1] POSIX Threads Programming:https://computing.llnl.gov/tutorials/pthreads/
[2] pthreads的基本用法:http://www.ibm.com/developerworks/cn/linux/l-pthred/
标签:
原文地址:http://www.cnblogs.com/shengshengwang/p/5694745.html