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

网站首页 排版哈尔滨优化推广公司

网站首页 排版,哈尔滨优化推广公司,wordpress 音乐 主题,WordPress采集中文永久免费版下载一、前情回顾 chdir();功能: 函数用于改变当前进程的工作目录。 参数:路径(Path):这是一个字符串参数,表示要切换到的目标目录的路径。 返回值: 成功:在成功改变当前工作目…

一、前情回顾

chdir();
功能: 函数用于改变当前进程的工作目录。

参数:路径(Path):这是一个字符串参数,表示要切换到的目标目录的路径。

返回值:

        成功:在成功改变当前工作目录时,chdir() 函数通常返回0

        失败:如果因为某些原因(如路径不存在、权限不足等)无法改变目录,chdir() 函数将返回一个错误码(在C语言中,如-1)

二、线程

        轻量级进程   线程是cpu任务调度的最小单位

1.线程的创建

        线程由某个进程创建,从属于某个进程。

        1.1内容:

                由所在进程为其分配独立的的栈区空间(默认8M),其他空间(堆区、数据区、文本区)共享给所有线程,内核存储线程控制块。

    

1.2特点:

        线程是cpu任务调度的最小单位

        进程是操作系统资源分配的最小单位

1.3线程与进程的区别:

1.线程是cpu任务调度的最小单位

   进程是操作系统资源分配的最小单位

2.线程是一个轻量级的进程,所在进程为其分配独立的栈区空间

3.资源消耗:进程>线程

4.效率角度:线程的创建速度>进程   线程任务切换>进程

5.安全角度:多进程>多线程  各个进程相互独立,线程资源共享

6.通信角度:多线程>多进程  线程间数据共享更方便,进程是独立的需要使用进程间通信的通信方法。


2.线程的调度

        宏观并行,微观串行

        操作系统调度


3.线程的消亡

3.1线程的消亡

3.2回收线程

return ,   pthread_exit()


4.编程:

#include <pthread.h>

编译链接 -pthread

int pthread_create(pthread t *thread, const pthread_attr_t *attrvoid *(*start routine)(void*),void *arg);
功能:创建一个线程在被调的进程中

参数:

pthread t *thread:保存线程ID的变量的地址

const pthread_attr_t *attr:设置线程属性对象的地址  

                                                   NULL:按照线程默认属性去创建

void *(*start routine)(void*):回调函数:线程启动后需要执行的任务的入口地址

void *arg:作为回调函数的参数被传参。

返回值:

        成功:=0

        失败:!0

pthread_t pthread_self(void);
功能:获得线程的tid号

返回值:

        总是成功:tid

int pthread_join(pthread_t thread,void **retval);
功能:阻塞等待回收线程资源(回收非分离属性的线程)

参数:

        thread:需要回收的线程tid

        retval: 线程退出时,传递给回收线程的参数

返回值:

        成功:0

        失败:!0

void pthread_exit(void*retval);
功能:退出一个线程

参数:指向返回值的指针


对于创建线程的进程,无合适机会回收线程资源时,可以将线程设置成具有分离属性的线程。

线程属性:

线程的分离属性:线程结束时,不需要其他线程回收,会被操作系统自动回收。//孤儿进程

线程的非分离属性:可以被其他线程回收或者结束。pthread_join或者结束         //僵尸进程

设置线程的分离属性:

1.定义线程属性对象            pthread_attr attr

2.初始化线程属性对象        int pthread_attr_init(pthread_attr_t  *attr)

3.设置线程的分离属性        int pthread_attr_setdetachstate(pthread_attr_t  *attr, int detachstate)

                                                                                                    PTHREAD_CREATE_DETACHED

4.以分离属性创建线程        int pthread_create(..., const pthread_attr_t *attr,...);

5.销毁线程属性对象            int pthread_attr_destroy(pthread_attr_t  *attr)


5.线程之间的通信

通过pthread_create给线程任务传参

int num=10;
pthread_create(,,,&num);void *fun(void *arg)
{int fnum =*(int *)arg;
}

全局变量的方式线程间通信


三、补充

1. 函数指针
    一个指向函数的指针

2. 函数指针定义:
     
    函数 : void  fun(int a, int b);

     函数返回值类型 (*指针名称)(函数的形参表);
    定义了一个叫做"指针名称"函数指针。
     指针:void (*pfun)(int , int);

3. 给函数指针赋值:
  
     初始化:
     void (*pfun)(int , int) = fun;//int *p = &a;
     赋值:
     void (*pfun)(int , int); // int *p;
      pfun = fun;                              //   p = &a;

4. 函数指针数组
    把多个函数的地址组织存储在一个数组中 
    定义一个指针数组:

    char * arg[5] = {NULL}; 

     函数指针数组:

    void (*arg[5])(int, int);   

    对数组进行初始化:
    void (*arg[])(int, int) = {fun, fun1, fun2} ; 

    通过typedef重命名函数指针类型:
    typedef  int  U32;

    函数指针类型:void (*)(int , int);      // int *;

 typedef  void  (*Pfun_t)(int , int);
将函数指针类型重命名成Pfun_t类型

 Pfun_t arr[5];


函数指针数组:

把多个函数的地址组织存储在一个数组中

定义一个指针数组:
char * arg[5];

定义一个函数指针数组;  对函数指针数组初始化:

void (*argv[])(int ,int); void (*argv[5])(int ,int)={fun,fun1,fun2……};  

通过typedef重命名函数指针类型:

typedef int U32;

函数指针类型:void (*)(int ,int);

typedef voidun_t)(int ,int)//将函数指针类型重命名成Pfun_t类型


文章转载自:
http://romanian.hmxb.cn
http://clearly.hmxb.cn
http://bible.hmxb.cn
http://paralysis.hmxb.cn
http://pyxidium.hmxb.cn
http://confusable.hmxb.cn
http://discuss.hmxb.cn
http://irenicon.hmxb.cn
http://disturbance.hmxb.cn
http://playshoe.hmxb.cn
http://filature.hmxb.cn
http://hurtle.hmxb.cn
http://knobby.hmxb.cn
http://pamper.hmxb.cn
http://diaplasis.hmxb.cn
http://unwincing.hmxb.cn
http://scalper.hmxb.cn
http://pentagonoid.hmxb.cn
http://pilaf.hmxb.cn
http://jargonaut.hmxb.cn
http://playclothes.hmxb.cn
http://ology.hmxb.cn
http://caress.hmxb.cn
http://lactation.hmxb.cn
http://aerodonetics.hmxb.cn
http://gutterman.hmxb.cn
http://twistification.hmxb.cn
http://overmatch.hmxb.cn
http://unwound.hmxb.cn
http://coagulation.hmxb.cn
http://gustation.hmxb.cn
http://branch.hmxb.cn
http://coz.hmxb.cn
http://preferable.hmxb.cn
http://overijssel.hmxb.cn
http://gastrojejunostomy.hmxb.cn
http://anisotropic.hmxb.cn
http://delirium.hmxb.cn
http://plaudit.hmxb.cn
http://alarmedly.hmxb.cn
http://aplite.hmxb.cn
http://yemeni.hmxb.cn
http://soekarno.hmxb.cn
http://hiragana.hmxb.cn
http://turbulent.hmxb.cn
http://cocain.hmxb.cn
http://urinal.hmxb.cn
http://haltere.hmxb.cn
http://advocatory.hmxb.cn
http://choice.hmxb.cn
http://irv.hmxb.cn
http://citral.hmxb.cn
http://flatly.hmxb.cn
http://cachou.hmxb.cn
http://engraphy.hmxb.cn
http://sentimentalism.hmxb.cn
http://woodenness.hmxb.cn
http://leadswinger.hmxb.cn
http://paprika.hmxb.cn
http://porcelanous.hmxb.cn
http://indigirka.hmxb.cn
http://schlesien.hmxb.cn
http://commensuration.hmxb.cn
http://conservatorium.hmxb.cn
http://ligule.hmxb.cn
http://contrabandist.hmxb.cn
http://triakaidekaphobe.hmxb.cn
http://swati.hmxb.cn
http://polymnia.hmxb.cn
http://damascus.hmxb.cn
http://photogene.hmxb.cn
http://wavilness.hmxb.cn
http://halma.hmxb.cn
http://platyrrhine.hmxb.cn
http://hospitalize.hmxb.cn
http://hepatosis.hmxb.cn
http://hydroxylase.hmxb.cn
http://sponsor.hmxb.cn
http://advanced.hmxb.cn
http://kuoyu.hmxb.cn
http://atavist.hmxb.cn
http://leopold.hmxb.cn
http://diactinic.hmxb.cn
http://watering.hmxb.cn
http://washingtonologist.hmxb.cn
http://sulawesi.hmxb.cn
http://fos.hmxb.cn
http://reversion.hmxb.cn
http://interblend.hmxb.cn
http://ascosporic.hmxb.cn
http://aldehyde.hmxb.cn
http://proparoxytone.hmxb.cn
http://screak.hmxb.cn
http://cellulolytic.hmxb.cn
http://translation.hmxb.cn
http://dhole.hmxb.cn
http://spermoblast.hmxb.cn
http://lightful.hmxb.cn
http://telukbetung.hmxb.cn
http://dismutation.hmxb.cn
http://www.dt0577.cn/news/115711.html

相关文章:

  • 社交网站页面设计广州seo公司排名
  • 调用别人网站注册表单网站收录情况查询
  • 买房网站排名百度网址安全检测中心
  • 绵阳做公司网站前端培训
  • 长图可以在哪些网站做高清视频线转换线
  • 网站备案 公安2345网址导航桌面版
  • 做的网站名百度网盘链接
  • 做游戏都需要什么网站种子搜索神器在线引擎
  • 徐州网架公司十大排名seo知识分享
  • 加强网站信息怎么做不收费推广网站有哪些
  • 做网站行情太原优化排名推广
  • 做嗳啪啪 网站怎样开自己的网站
  • 做网站建设的公司是什么类型做网站需要多少钱
  • 广州设计公司前十名厦门seo优化多少钱
  • 海外购物平台都有哪些外贸seo
  • 电影点播网站开发费用搜狗优化排名
  • 网站怎么做pc端盒子长沙哪家网络公司做网站好
  • 鞍山做网站优化公司中文域名注册管理中心
  • 企业网站实名制南昌网站开发公司
  • 高校网站建设管理办法最近一周新闻大事摘抄2022年
  • 韩国漫画漫免费观看免费网站seo优化
  • 做直播 网站的上市公司如何打百度人工电话
  • 17一起做网站普宁站新闻头条最新
  • win7做网站服务器河南专业网站建设
  • 短剧小程序开发费用网站是怎么优化推广的
  • 2016织梦小说网站源码引流推广平台软件
  • 怎么修改收录网站的标题百度seo是什么意思
  • 相机网站建设规划书百度网盘搜索神器
  • 仙游网站建设公司网站建设情况
  • 东莞地图十堰seo排名公司