热门

最新

红包

立Flag

投票

同城

我的

发布
qq_58366207
qq_58366207
3 年前
trueqq_58366207

#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<unistd.h>
#include<pthread.h>
int con=10;
void *t_func1(void *arg)
{
con=100;
return ((void*)0);
}
void *t_func2(void *arg)
{
con=200;
return ((void*)0);
}

int main()

{
pthread_t tid1;//线程编号,线程id
pthread_t tid2;

pthread_create(&tid1,NULL,t_func1,NULL);//最后一个NULL,指示不用传数据
pthread_create(&tid2,NULL,t_func2,NULL);//最后一个NULL,指示不用传数据

sleep(2);//休眠一会,让线程先有机会执行完
printf("%d\n",con);
return(0);//main函数中的return等价exit()系统调用,退出线程
}

CSDN App 扫码分享
分享
评论
点赞
打赏
  • 复制链接
  • 举报
下一条:
整理网站页面CV的《长恨歌》文本,python字符串基础知识应用实战。这是一段由聊天引出的代码应用学习笔记链接地址:https://blog.csdn.net/m0_57158496/article/details/127894055
立即登录