31 lines
463 B
C
31 lines
463 B
C
|
#include<pthread.h>
|
||
|
#include<unistd.h>
|
||
|
#include<stdio.h>
|
||
|
void * thread(void *str)
|
||
|
{
|
||
|
int i;
|
||
|
for(i=0;i<6;++i)
|
||
|
{
|
||
|
sleep(2);
|
||
|
printf("This is the thread: %d\n", i);
|
||
|
}
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
pthread_t pth;
|
||
|
int i;
|
||
|
int ret;
|
||
|
ret=pthread_create(&pth,NULL,thread,(void *)(i));
|
||
|
printf("Test start\n");
|
||
|
for(i=0;i<6;++i)
|
||
|
{
|
||
|
sleep(1);
|
||
|
printf("This is the main: %d\n",i);
|
||
|
}
|
||
|
|
||
|
pthread_join(pth,NULL);
|
||
|
return 0;
|
||
|
}
|