- 论坛徽章:
- 0
|
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
void * test(void * arg)
{
printf("%lu : %dn", pthread_self(), *(int *)arg);
}
int main()
{
int i, thread[5];
for(i=0;i<5;i++)
{
if( pthread_create(&thread[i], NULL, &test, &i)!=0 )
{
return -1;
}
printf("create thread--%d-- okn",i);
}
}
|
输出:(open SUSE 11.1)
3085187984 : 0
create thread--0-- ok
3076795280 : 1
create thread--1-- ok
3068402576 : 2
create thread--2-- ok
3060009872 : 3
create thread--3-- ok
3051617168 : 4
create thread--4-- ok |
|
|