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

杭州91网站建设如何查询网站域名备案信息

杭州91网站建设,如何查询网站域名备案信息,怎么做物流网站,响应式网站的优势有那些的呢目录 一、基础知识 1.优点 2.概念 3.特征 4.缺点 二、线程与进程联系与区别 1.联系 2.区别 三、线程的设计框架 posix 1.步骤 2.创建多线程 pthread_create 2.1头文件 2.2函数原型 2.3功能 2.4参数 2.5返回值 2.6注意 2.7代码示例 2.获得线程号pthread_sel…

目录

一、基础知识

1.优点

2.概念

3.特征

4.缺点

二、线程与进程联系与区别

1.联系

2.区别

三、线程的设计框架  posix

1.步骤

2.创建多线程 pthread_create

2.1头文件

2.2函数原型

2.3功能

2.4参数

2.5返回值

2.6注意

2.7代码示例

2.获得线程号pthread_self

2.1函数原型

2.2功能

2.3参数

2.4返回值

2.5代码示例

四、线程的退出

1.自行退出 ==》自杀  ==》子线程自己退出

pthread_exit

1.1函数原型

1.2功能

1.3参数

1.4返回值

1.5代码示例

2.强制退出 ==》他杀  ==》主线程结束子线程

pthread_cancel

2.1函数原型

2.2功能

2.3参数

2.4返回值

2.5代码示例

五、线程的回收

1.pthread_join

1.1函数原型 

1.2功能

1.3参数

1.4返回值

1.5子线程的回收策略

1.6代码示例

六、线程的参数,返回值

1、传参数

2.代码示例

一、基础知识

1.优点

比多进程节省资源,可以共享变量。

2.概念

1)线程是轻量级进程,一般是一个进程中的多个任务。

2)进程是系统中最小的资源分配单位

3)线程是系统中最小的执行单位

3.特征

3.1共享资源

3.2效率高  30%

3.3三方库: pthread  clone   posix
1) 编写代码头文件: pthread.h
2) 编译代码加载库: -lpthread   library 
                                    libpthread.so
                                    gcc 1.c -lpthread 

4.缺点

1)线程和进程相比,稳定性,稍微差些
2)线程的调试gdb,相对麻烦些。
info thread 

二、线程与进程联系与区别

1.联系

线程属于某个进程

2.区别

1)线程比进程多了共享资源。  IPC
线程又具有部分私有资源。
进程间只有私有资源没有共享资源。

2)进程空间独立,不能直接通信。
线程可以共享空间,可以直接通信。(栈区独立)

3)当进程运行起来后,默认有一个线程。主线程

4)线程与线程,平级。主次之分

5)创建的开销不同。进程3G。线程8M栈区独立

6)稳定性。线程弱,进程强。

三、线程的设计框架  posix

1.步骤

创建多线程 --->线程空间操作 --->线程资源回收

errno   strerror(errno)  perror();

2.创建多线程 pthread_create

2.1头文件

#include<pthread.h>

2.2函数原型

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

2.3功能

该函数可以创建指定的一个线程。

2.4参数

thread             线程id,需要实现定义并由该函数返回。
attr                  线程属性,一般是NULL,表示默认属性。
start_routine   指向指针函数的函数指针。
   本质上是一个函数的名称即可。称为
th 回调函数,是线程的执行空间。
{
}
arg  回调函数的参数,即参数3的指针函数参数。

2.5返回值

成功 0
失败 错误码

2.6注意

1)一次pthread_create执行只能创建一个线程。

2)每个进程至少有一个线程称为主线程。

3)主线程退出则所有创建的子线程都退出。 

4)主线程必须有子线程同时运行才算多线程程序。

5)线程id是线程的唯一标识,是CPU维护的一组数字。

6)pstree 查看系统中多线程的对应关系。

7)多个子线程可以执行同一回调函数。

8)ps -eLf 查看线程相关信息Low Weigth Process

9)ps -eLo pid,ppid,lwp,stat,comm

2.7代码示例

#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
void *th1(void *arg)
{while (1){printf("发视频1...\n");sleep(3);}return NULL;
}
void *th2(void *arg)
{while (1){printf("发视频2...\n");sleep(2);}return NULL;
}int main(int argc, char **argv)
{pthread_t tid;pthread_create(&tid, NULL, th1, NULL);pthread_create(&tid, NULL, th1, NULL);while (1){sleep(1);}// system("pause");return 0;
}

2.获得线程号pthread_self

2.1函数原型

pthread_t pthread_self(void); unsigned long int; %lu

2.2功能

获取当前线程的线程id

2.3参数

2.4返回值

成功 返回当前线程的线程id
失败  -1;

2.5代码示例

#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
void *th1(void *arg)
{while (1){printf("发送视频1...tid:%lu\n", pthread_self());sleep(1);}return NULL;
}
void *th2(void *arg)
{while (1){printf("接受视频2...tid:%lu\n", pthread_self());sleep(1);}return NULL;
}int main(int argc, char **argv)
{pthread_t tid1, tid2;pthread_create(&tid1, NULL, th1, NULL);pthread_create(&tid2, NULL, th1, NULL);while (1){printf("main tid:%lu\n", pthread_self());sleep(1);}// system("pause");return 0;
}

四、线程的退出

1.自行退出 ==》自杀  ==》子线程自己退出

pthread_exit

整个退出

exit(1);

1.1函数原型

void pthread_exit(void *retval);  exit  return p;

1.2功能

子线程自行退出

1.3参数

retval 线程退出时候的返回状态,临死遗言。

1.4返回值

1.5代码示例

#include <pthread.h>
#include <stdio.h>
#include <unistd.h>void* th(void* arg)
{int i = 5;while (i--){printf("th is %lu\n", pthread_self());sleep(1);}pthread_exit(NULL);// return NULL; 从功能角度描述,两者一致。建议调用pthread_exit();
}int main(int argc, char** argv)
{pthread_t tid;pthread_create(&tid, NULL, th, NULL);while (1){sleep(1);}// system("pause");return 0;
}

2.强制退出 ==》他杀  ==》主线程结束子线程

pthread_cancel

2.1函数原型

int pthread_cancel(pthread_t thread);

2.2功能

请求结束一个线程

2.3参数

thread 请求结束一个线程tid

2.4返回值

成功 0
失败 -1;

2.5代码示例

// #include <bits/pthreadtypes.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>void *th(void *arg)
{int i = 5;while (i--){printf("tid is %lu\n", pthread_self());sleep(1);}pthread_exit(NULL);
}int main(int argc, char **argv)
{pthread_t tid;pthread_create(&tid, NULL, th, NULL);int i = 0;while (1){printf("main tid:%lu ,i:%d\n", pthread_self(), i);sleep(1);i++;if (5 == i){pthread_cancel(tid);}}// system("pause");return 0;
}

五、线程的回收

线程的回收机制 ====》不同与进程没有孤儿线程和僵尸线程。====》主线程结束任意生成的子线程都会结束。====》子线程的结束不会影响主线程的运行。

1.pthread_join

1.1函数原型 

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

1.2功能

通过该函数可以将指定的线程资源回收,该函数具有
           阻塞等待功能,如果指定的线程没有结束,则回收线程会阻塞。

1.3参数

thread  要回收的子线程tid
retval  要回收的子线程返回值/状态。==》ptread_exit(值);

1.4返回值

成功 0
失败 -1;

1.5子线程的回收策略

  1)如果预估子线程可以有限范围内结束则正常用pthread_join等待回收。
  2)如果预估子线程可能休眠或者阻塞则等待一定时间后强制回收。
  3)如果子线程已知必须长时间运行则,不再回收其资源。

1.6代码示例

#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
void *th(void *arg)
{int i = 5;while (i--){printf("tid is %lu\n", pthread_self());sleep(1);}pthread_exit(NULL);
}int main(int argc, char **argv)
{//*改变指针指向的内容//**改变指针的指向pthread_t tid;pthread_create(&tid, NULL, th, NULL);pthread_join(tid, NULL);printf("th is end\n");// system("pause");return 0;
}

六、线程的参数,返回值

1、传参数

传整数  ---------》int add(int a,int b);    ///a b 形参
add(x,y);    ////x y 实参 

2.代码示例


#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
void* th(void*arg)
{char* tmp = (char*)arg;  //void* ->  char* strcat(arg,",world");return arg;
}int	main(int argc, char **argv)
{char buf[128]="hello";pthread_t tid;pthread_create(&tid,NULL,th,buf);// 任意类型指针到void*  不需要强转void* ret;pthread_join(tid,&ret);printf("buf:%s\n",(char*)ret);//printf("buf:%s\n",buf);//system("pause");return 0;
}


文章转载自:

http://hyMWOITC.rqknq.cn
http://4mSGCrlj.rqknq.cn
http://WYJagoQs.rqknq.cn
http://lwG2Pzkz.rqknq.cn
http://LPE0moXQ.rqknq.cn
http://VlhybCkg.rqknq.cn
http://BWBdHXh6.rqknq.cn
http://vjTunlJI.rqknq.cn
http://OpiWYWq8.rqknq.cn
http://NaIrSk9Z.rqknq.cn
http://1wb1ctYY.rqknq.cn
http://hPEAURbn.rqknq.cn
http://EfutdIVe.rqknq.cn
http://PGCGJgkj.rqknq.cn
http://r09qy3QZ.rqknq.cn
http://5eQbChpi.rqknq.cn
http://3AQD7h0W.rqknq.cn
http://FdXEmZuK.rqknq.cn
http://pyqdNpvX.rqknq.cn
http://Fikco0hd.rqknq.cn
http://KU4uTlnZ.rqknq.cn
http://b0h4ABNy.rqknq.cn
http://BWOALPle.rqknq.cn
http://RyF5p7OJ.rqknq.cn
http://Z9rcHy2L.rqknq.cn
http://iVy7JpvD.rqknq.cn
http://hQObHMwd.rqknq.cn
http://sBhBrpTt.rqknq.cn
http://6kTAV5UV.rqknq.cn
http://NXWu8Fr1.rqknq.cn
http://www.dtcms.com/wzjs/605408.html

相关文章:

  • 做设计任务的网站郑州百姓网官网
  • 医疗网站不备案衡水做网站开发的
  • 佛山网站外包wordpress 搭建会员
  • 做网站有地区差异吗网站建设 推广什么意思
  • 漂亮的网站维护页面中信建设有限责任公司
  • 网站建设销售福建省建设工程注册管理中心网站
  • 建设信息门户网站的条件长沙网站建设大全
  • 南京哪家做网站比较好柳州哪里有网站建设
  • 手机网站制作价格简易东莞网站制作公司
  • 中企动力做的网站被镜像哪里可以做拍卖网站
  • 郑州服饰网站建设建设工程包括什么工程
  • 网站链接建设及引流营销温江做网站
  • 公众号平台登录邵武网站建设wzjseo
  • 河南省建设厅督察网站网站建设需不需要招标
  • 网页站点文件夹wordpress免费汽车配件企业主题
  • 手机网站演示贵阳市网站优化
  • 优秀企业门户网站安徽网站优化价格咨询
  • 该网站正在建设网站价格
  • 道滘镇网站仿做做微信扫码网站
  • 自己可以做网站生意好做吗快乐麻花网站源码
  • 网站开发语言总结有哪些智慧旅游网站建设方案
  • 中国手表网站哈尔滨建设信息网官网
  • 网站需求报告怎么写自己怎么做网站网页
  • 领导高度重视网站建设广州大型网站建设
  • 教学系统设计 网站开发建设执业资格注册中心网站
  • 不锈钢网站样板wordpress轮播
  • 网站打包app公司如何组建网站
  • 北京商城网站建设地址网站设计背景图片怎么做的
  • 国内做网站建设好的余姚网站建设维护最新招聘信息
  • 有没有便宜的网站建设美术主题资源网站建设