关于pthread | create()||参数| thread | function | pt的第四个参数

电脑杂谈  发布时间:2020-07-17 10:17:46  来源:网络整理

pthread_create 第一个参数_pthread_create函数参数_pthread_create第一个参数

C用于在Linux下开发多线程程序. Linux系统下的多线程遵循POSIX线程接口,称为pthreads.

这是百度百科上的定义:

#include

pthread_create 第一个参数_pthread_create第一个参数_pthread_create函数参数

intpthread_create(pthread_t * restricttidp,constpthread_attr_t * restrictattr,void *(* start_rtn)(void)pthread_create函数参数,void * restrictarg);

返回: 0ifOK,错误编号失败

由strict修改的指针是最初访问该指针所指向的对象的唯一方法. 仅当第二个指针基于第一个指针时,才可以访问该对象. 对对象的访问仅限于由strict修改的指针表达式. 由strict修改的指针主要用于函数参数或指向由malloc()分配的内存空间. 限制数据类型不会更改程序的语义. 通过假设受限指针是访问对象的唯一方法,编译器可以更好地优化某些类型的例程.

pthread_create函数参数_pthread_create第一个参数_pthread_create 第一个参数

第一个参数是指向线程标识符的指针.

第二个参数用于设置线程属性.

第三个参数是线程运行函数的起始地址.

pthread_create第一个参数_pthread_create 第一个参数_pthread_create函数参数

最后一个参数是运行函数的参数.

传递参数时,可以直接传递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;
}

pthread_create第一个参数_pthread_create 第一个参数_pthread_create函数参数

Unix说:

如果需要将多个参数传递给start_rtn函数,则需要将这些参数放入一个结构中,然后将该结构的地址作为arg参数传递.

上述函数foo(int * apthread_create函数参数,int * b);可以传递2个参数!

问,第四个参数void * restrictarg有什么用?运行功能参数是什么意思?


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-283425-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      • 隋恭帝杨侑
        隋恭帝杨侑

        暖宝宝

      • 伊藤舞子
        伊藤舞子

        是封建社会独有的东西

      • 伍冲虚
        伍冲虚

        球员们感觉自己的压力更大了

      热点图片
      拼命载入中...