当前位置: 首页 > news >正文

外网网站有什么好的推荐seo搜索优化待遇

外网网站有什么好的推荐,seo搜索优化待遇,宁波学校网站建设,遵义网站制作1、Pthread 库说明 pthread 库是Linux系统默认线程库。 在Linux 系统环境中&#xff0c;编辑C/C程序使用pthread 库&#xff0c;需要添加对应的头文件&#xff0c;并链接pthread库。 #include<pthread.h> 2、Pthread 库核心方法 pthread_create 函数定义&#xff1…

1、Pthread 库说明

pthread 库是Linux系统默认线程库。

在Linux 系统环境中,编辑C/C++程序使用pthread 库,需要添加对应的头文件,并链接pthread库。

#include<pthread.h>

2、Pthread 库核心方法

pthread_create

函数定义:

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

参数说明: 

pthread_t 定义如下:

typedef unsigned long int pthread_t;

thread 是一个指向线程标识符的指针,线程调用后,改值被设置为线程ID

attr 用来设置线程属性

start_routine 是线程函数的其实地址,即线程函数体,线程创建成功后,thread 指向的内存单元从该地址开始运行

arg 是传递给线程函数体的参数

返回值:

若线程创建成功,则返回0,失败则返回错误码,并且 thread 内容是未定义的。

pthread_join

函数定义:

int pthread_join(pthread_t thread, void **retval);

参数说明: 

thread 是线程表示符

retval 用来获取线程的返回值,一般是 pthread_join 方法传递出来的值

功能说明:

这是一个线程阻塞函数,调用该函数则等到线程结束才继续运行

pthread_exit

函数定义:

void pthread_exit(void *retval);

参数说明: 

retval 是线程的退出码,传递给创建线程的地方

功能说明:

一个线程的结束有两种途径:

  • 线程函数体执行结束;
  • 调用 pthread_exit 方法退出线程;

pthread_self

函数定义:

pthread_t pthread_self();

功能说明:

用来获取当前线程ID

pthraad_detach

函数定义:

int pthread_detach (pthread_t __th)

功能说明:

分离线程

3、Pthread 库线程属性说明

线程属性 

设置线程不同属性有不同属性有不同的方法,但是都需要先初始化属性数据结构,初始化函数为:

int pthread_attr_init(pthread_attr_t *__attr);

线程属性包括:

  1. 作用域;
  2. 栈大小;
  3. 栈地址;
  4. 优先级;
  5. 分离状态;
  6. 调度策略;
  7. 调度参数;

 分离状态

线程终止时,系统将不再保留线程终止状态;当不需要线程的终止状态时,可以分离线程(调用 pthread_detach 函数),也可以通过设置线程的分离状态实现

int pthread_attr_getdetachstate(const pthread_attr_t* attr, int* state);
int pthread_attr_setdetachstate(pthread_attr_t* attr, int state);

state 的值可以是 PTHREAD_CREATE_DETACHED 和 PTHREAD_CREATE_JOINABLE,分别表示主线程阻塞和子线程剥离

线程优先级 

新线程的优先级默认为0

int  pthread_attr_getschedparam(const pthread_attr_t *restrict attr, struct sched_param *restrict param) ;
int pthread_attr_setschedparam(pthread_attr *restrict attr, const struct sched_param* restrict param);

继承父优先级 

新线程不继承父线程的调度优先级

调度策略

线程使用 SCHED_OTHER 调度策略,线程一旦开始运行,直到被强占或者直到线程阻塞或者停止位置

int pthread_attr_setschedpolicy(pthread_attr_t* attr, int policy);
int pthread_attr_setschedparam(pthread_attr_t* attr, struct sched_param* param)

4、Pthread 示例代码

前提:在/usr/local/source_code目录下新增thread_demo 目录,并在此目录下新建init_thread.cpp,文件内容如下:

#include <pthread.h>
#include <iostream>using namespace std;void* printHello(void* args) {cout << "Hello World from Thread" << endl;return NULL;
}int main() {pthread_t thread;if (pthread_create(&thread, NULL, &printHello, NULL)) {cout << "Error creating thread" << endl;return 1;}if (pthread_join(thread, NULL)) {cout << "Error joining thread" << endl;return 2;}return 0;
}

编译执行:

g++ init_thread.cpp -o init_thread  -L/usr/local/lib/ -lpthread

控制台输出:

[root@localhost thread_demo]# g++ init_thread.cpp -o init_thread  -L/usr/local/lib/ -lpthread
[root@localhost thread_demo]# ll
总用量 16
-rwxr-xr-x. 1 root root 9136 10月 24 14:44 init_thread
-rw-r--r--. 1 root root  459 10月 24 14:30 init_thread.cpp
[root@localhost thread_demo]# ./init_thread
Hello World from Thread

http://www.shuangfujiaoyu.com/news/36270.html

相关文章:

  • 做动态网站费用建网站怎么建
  • 做网站建设需要会哪些淘宝标题优化工具推荐
  • 凤岗仿做网站北京seo优化诊断
  • 竞价托管如何托管seo技术培训东莞
  • 济南建设网站国外网页模板
  • 做购物网站需要什么资质百度免费广告发布平台
  • 大德通网站建设网站长尾关键词排名软件
  • php做网站都需要学什么湖南企业竞价优化首选
  • 微信公众号关联网站搜索引擎网站大全
  • 电子商务网站建设论文总结北京网站seo招聘
  • wordpress换了固定链接404衡水seo排名
  • 开源自动化运维平台seo免费培训教程
  • 做交通事故的网站网站是如何建立的
  • 某网站自己做中性笔整站排名优化品牌
  • 做美食如何加入团购网站推广游戏赚钱的平台
  • 网站开发工程师制作kpi营销技巧和营销方法心得
  • 个人可以建新闻网站吗百度推广外包
  • 建设工程学部研究生培养网站免费网站模板
  • 培训机构网站制作关键词查询的五种常用工具
  • 毕设做网站可以得高分吗重庆seo标准
  • wordpress wpenqueuescriptsseo网站快速排名外包
  • 如何制作flash网站百度平台商家app下载
  • 点广告挣钱网站有哪些西安推广平台排行榜
  • 网站建设和优司怎么样独立站seo推广
  • 网站404怎么做视频教程com域名
  • 杭州企业画册设计公司徐州seo企业
  • 个人做外贸网站平台有哪些seo变现培训
  • html编辑器软件seo服务 收费
  • wordpress 出现广告苏州seo推广
  • wordpress自定义菜单输出手机优化大师为什么扣钱