linux 编写一个多线程程序,要求主线程创建3个子线程,3个子线程在执行时都修改一个他们的共享变量。

2025-02-24 00:51:16
推荐回答(2个)
回答1:

void func1(int n)
{
printf("%d",n*10);
}
void func1(int n)
{
printf("%d",n-10);
}

void func1(int n)
{
printf("%d",n/2);
}

int main(void)
{
int n = 10;
pthread_t 1_thread,2_thread,3_thread;
pthread_create(1_thread,NULL,func1,n);
pthread_create(2_thread,NULL,func2,n);
pthread_create(3_thread,NULL,func3,n);
return 0;
}

回答2:

楼上好专业!我也想问的!