c++ 多线程

1.调用windows API实现多线程

h1=CreateThread(NULL,0,myfun1,NULL,0,NULL);//创建线程1

2、Linux

int ret = pthread_create( &tids[i], NULL, say_hello, NULL );

//参数:创建的线程id,线程参数,线程运行函数的起始地址,运行函数的参数

3、c++11

thread th1(t1);

https://chorior.github.io/2017/04/24/C++-thread-basis/

 

ps:报错:int nRet = pthread_create(&tids, NULL, (void*(*)(void*))listenClient1(), NULL);

int nRet = pthread_create(&tids, NULL, listenClient1, NULL);出错:No matching function for call to 'pthread_create'

 

调用函数名字前面缺少:(void*(*)(void*)),因为:ios接口这样的

int pthread_create(pthread_t _Nullable * _Nonnull __restrict,
		const pthread_attr_t * _Nullable __restrict,
		void * _Nullable (* _Nonnull)(void * _Nullable),
		void * _Nullable __restrict);

2ps:出错没有开辟新新线程,一直阻塞在listenClient1:int nRet = pthread_create(&tids, NULL, (void*(*)(void*))listenClient1(), NULL);

修改:int nRet = pthread_create(&tids, NULL, (void*(*)(void*))listenClient1, NULL);

完事!

待更新新问题!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值