您现在的位置是:主页 > news > 苏州企业网站建设/管理培训

苏州企业网站建设/管理培训

admin2025/5/16 8:29:55news

简介苏州企业网站建设,管理培训,网站建设消费者群体分析,js获取网站域名在Linux下创建的线程的API接口是pthread_create(),它的完整定义是: int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*) void *arg); 当你的程序调用了这个接口之后,就会产生一个线程,而这个线程的入口函数就是start_r…

苏州企业网站建设,管理培训,网站建设消费者群体分析,js获取网站域名在Linux下创建的线程的API接口是pthread_create(),它的完整定义是: int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*) void *arg); 当你的程序调用了这个接口之后,就会产生一个线程,而这个线程的入口函数就是start_r…

在Linux下创建的线程的API接口是pthread_create(),它的完整定义是:

int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*) void *arg);  

当你的程序调用了这个接口之后,就会产生一个线程,而这个线程的入口函数就是start_routine()。如果线程创建成功,这个接口会返回0。

start_routine()函数有一个参数,这个参数就是pthread_create的最后一个参数arg。这种设计可以在线程创建之前就帮它准备好一些专有数据,最典型的用法就是使用C++编程时的this指针。start_routine()有一个返回值,这个返回值可以通过pthread_join()接口获得。

pthread_create()接口的第一个参数是一个返回参数。当一个新的线程调用成功之后,就会通过这个参数将线程的句柄返回给调用者,以便对这个线程进行管理。

pthread_create()接口的第二个参数用于设置线程的属性。这个参数是可选的,当不需要修改线程的默认属性时,给它传递NULL就行。

#include <stdio.h>
#include <pthread.h>
void* thread( void *arg )
{printf( "This is a thread and arg = %d.\n", *(int*)arg);*(int*)arg = 0;return arg;
}
int main( int argc, char *argv[] )
{