|
发表于 2008-2-25 15:06:26
|
显示全部楼层
- #include <iostream>
- #include <pthread.h>
- using namespace std;
- static void* foo(void* arg);
- static void* foo(void* arg)
- {
- cout <<"########" << endl;
- return NULL;
- }
- int main()
- {
- pthread_t pid[5];
- int i;
- for (i = 0; i < 5; i++)
- {
- if (pthread_create(&pid[i], NULL, foo, (void*) i))
- {
- cout << "create thread error!" << endl;
- return -1;
- }
- }
- for (i = 0; i < 5; i++)
- {
- pthread_join(pid[i], NULL);
- }
- return 0;
- }
复制代码
编译的时候要-lpthread |
|