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);
完事!
待更新新问题!