📄 pthread.c
字号:
#include <stdio.h>
#include <stdlib.h>#include <unistd.h>
#include <pthread.h>
#include <signal.h>
void *test2(void);void *test3(void);
pthread_t th_1,th_2,th_3;
void *v1,*v2,*v3;
void *test1(void)
{
char c=0;
printf("Test1\n");
while(1)
{
c=getchar();
if(c=='2')
{
pthread_cancel(th_2);
printf("Kill a thread\n");
}
if(c=='3')
{
pthread_cancel(th_3);
printf("Kill a thread\n");
}
if(c=='k')
{
pthread_create( &th_2,NULL,test2,0 );
printf("start a thread\n");
} if(c=='s')
{
pthread_create( &th_3,NULL,test3,0 );
printf("start a thread\n");
}
}
return NULL;
}
void *test2(void)
{
char a[100]="/bin/cs 2 2000 /var/tmp/f1.txt";
printf("Test 2\n");
system( a );
return NULL;
}
void *test3(void)
{ int i=0;
for( i=0;i<1000;i++ )
{
printf("Test3=%d\n",i);
}
return NULL;
}
int main()
{
pthread_create( &th_1,NULL,test1,0 );
//pthread_create( &th_2,NULL,test2,0 );
pthread_create( &th_3,NULL,test3,0 );
pthread_join( th_1,&v1 );
//pthread_join( th_2,&v2 );
pthread_join( th_3,&v3 );
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -