
C用于在Linux下开发多线程程序. Linux系统下的多线程遵循POSIX线程接口,称为pthreads.
这是百度百科上的定义:
#include

intpthread_create(pthread_t * restricttidp,constpthread_attr_t * restrictattr,void *(* start_rtn)(void)pthread_create函数参数,void * restrictarg);
返回: 0ifOK,错误编号失败
由strict修改的指针是最初访问该指针所指向的对象的唯一方法. 仅当第二个指针基于第一个指针时,才可以访问该对象. 对对象的访问仅限于由strict修改的指针表达式. 由strict修改的指针主要用于函数参数或指向由malloc()分配的内存空间. 限制数据类型不会更改程序的语义. 通过假设受限指针是访问对象的唯一方法,编译器可以更好地优化某些类型的例程.

第一个参数是指向线程标识符的指针.
第二个参数用于设置线程属性.
第三个参数是线程运行函数的起始地址.

最后一个参数是运行函数的参数.
传递参数时,可以直接传递void *(* start_rtn)(void),例如:
#include
#include
void* foo(int *a,int *b)
{
printf("pthread :%dn",++*a);
printf("pthread :%dn",++*b);
}
int main()
{
int a=0;
int b=0;
pthread_t tid;
int err;
err=pthread_create(&tid,NULL,foo(&a,&b),NULL);
foo(&a,&b);
return 0;
}

Unix说:
如果需要将多个参数传递给start_rtn函数,则需要将这些参数放入一个结构中,然后将该结构的地址作为arg参数传递.
上述函数foo(int * apthread_create函数参数,int * b);可以传递2个参数!
问,第四个参数void * restrictarg有什么用?运行功能参数是什么意思?
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-283425-1.html
是封建社会独有的东西
球员们感觉自己的压力更大了
暖宝宝