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

网站关键词优化排名要怎么做bt磁力搜索引擎索引

网站关键词优化排名要怎么做,bt磁力搜索引擎索引,做减肥网站,南昌媒体网站建设口碑推荐线程和进程 以前我们要同时跑多个程序,可以通过fork()多个子进程,然后通过系统函数进行程序的替换,但是创建进程代价大,不仅要拷贝一份父进程的地址空间,页表,文件表述符表等。但是线程不需要因为是进程的…


线程和进程

以前我们要同时跑多个程序,可以通过fork()多个子进程,然后通过系统函数进行程序的替换,但是创建进程代价大,不仅要拷贝一份父进程的地址空间,页表,文件表述符表等。但是线程不需要因为是进程的执行流,共享同个地址空间,页表,只需让不同线程执行不同的代码块(函数就可以了)。

一、线程函数接口

它们的返回值都比较统一,成功就返回0,失败就返回错误码

(1)线程创建

第一个参数类型是我们在定义的一个pthread_t类型的变量指针,通过它我们可以拿到 用户识别的线程id。第二个参数设置为空。第三个参数是函数指针,第四个是我们要传入线程执行函数的参数,由于它的类型是void*,我们可以传入任意类型

(2)线程等待 

线程和进程一样,虽然是一个进程的地址空间的执行流,但是也要进行等待回收,不然会造成类似内存泄漏 问题。retval是输出型参数,通过它可以拿到线程退出信息(简单说就是线程执行函数的返回值)。

(3)线程中止

 进程有退出码,线程没有,只有我们自己写的返回值,既用pthread_exit()返回,或者直接return返回自定义的码(由于返回值类型是void*,要强转),不建议用exit()因为会造成主线程退出,主线程退出了,进程资源就释放了,所有线程就跟着退出了。通常这返回值信息会被线程等待函数pthread_join()拿到。


(4)线程分离 

 以前子进程退出如果父进程不进行等待,我们可以自定义捕捉函数对子进程发出的退出信号进行忽略,不会有僵尸进程。线程也可以通过分离,让主线程不用主动对它进行等待,就算线程退出也不会有类型内存泄漏问题。注意的是,线程分离只是一种工作状态,它和没分离的线程几乎一样,只是不用等待了。

二,多线程的创建

pthread_create函数参数由于是void*,我们就可以传任意类型的对象

makefile

test:classpthreads.ccg++ -o  $@ $^ -std=c++11 -lpthread 
.PHONY:clean
clean:rm -f test

 classpthreads.cc

#include<iostream>
using namespace std;
#include<pthread.h>
#include<unistd.h>
#include<string.h>
#include <sys/types.h>
#include<vector>namespace ljh{
class Task{
public:
Task():datex(0),datey(0)
{}
void SetDate(int x,int y)
{datex=x;datey=y;
}
int Excute()
{return datex+datey;
}
~Task()
{}private:int datex;int datey;};
class threaddate:public Task
{
public:threaddate(int x,int y,char* threadname ):_x(x),_y(y),_threadname(threadname){s.SetDate(_x,_y);}string getname(){return _threadname;}int run(){s.Excute();}private:
string _threadname;
int _x;
int _y;
Task s;};
class Result{
public:
void SetResult(int result,string& threadname)
{_result=result;_threadname=threadname;}
void Print()
{cout<<"result:"<<_result<<"threadname"<<_threadname<<endl;}
private:int _result;string _threadname;
};}using namespace ljh;
void* handlerTask(void*p)
{threaddate* td=static_cast<threaddate*>(p);
string name=td->getname();
Result* result=new Result();
int ret=td->run();
result->SetResult(ret,name);
delete td;
sleep(2);
return result;}vector<Result*>  ret;
vector<pthread_t> pthreadname;
int main()
{for(int i=0;i<5;i++)//创建5个线程{char* name=new char[64];pthread_t id;snprintf(name,sizeof(name),"Thread_%d",i+1);threaddate* p=new threaddate(2,6,name);pthread_create(&id,nullptr,handlerTask,p);pthreadname.push_back(id);}for(auto e:pthreadname){  void* s=nullptr;//返回值,void*pthread_join(e,&s);//线程等待回收ret.push_back((Result*)s);}return 0;
}

三.创建的线程和主线程之间关系

1.多线程只是主线程的执行流,主线程main退出,子进程也会退出,所以我们必须让主线程最后退出

2.创建的新线程和主线程,哪个先运行,这个取决与调度器。

线程共享和私有

(1)共享:代码和全局数据和进程文件描述符表

因为它们拥有同一块地址空间

(2)私有:线程的硬件上下文数据(cpu寄存器的值),线程的独立栈结构。对于多进程来说,线程的上下文数据比进程少,所以也叫线程为轻量级进程。

我们可以用命令查看(ps -aL | grep  xxx).对于栈来说,不同线程可以分为进程地址空间的栈空间还有线程独立的栈,访问全局数据就时访问进程地址空间主栈,在线程执行函数里面变量之类的就是线程独立的栈。

验证:创建3个线程,定义一个全局变量vale,还有线程执行函数的n,不同的线程打印全局vale地址是相同,n的地址却是不同的。


文章转载自:
http://dinncoluteal.tpps.cn
http://dinncobeefburger.tpps.cn
http://dinncoclicket.tpps.cn
http://dinncopeneplain.tpps.cn
http://dinncozaptiah.tpps.cn
http://dinncofaff.tpps.cn
http://dinncomastoideal.tpps.cn
http://dinncolentiginous.tpps.cn
http://dinncoarno.tpps.cn
http://dinncopowerfully.tpps.cn
http://dinncoincrimination.tpps.cn
http://dinncosyphilis.tpps.cn
http://dinncomultivallate.tpps.cn
http://dinncoasymptomatically.tpps.cn
http://dinncolegitimacy.tpps.cn
http://dinncosaleslady.tpps.cn
http://dinncofritted.tpps.cn
http://dinncotaranto.tpps.cn
http://dinncoillusionism.tpps.cn
http://dinncobatholithic.tpps.cn
http://dinncofoundling.tpps.cn
http://dinncoabhor.tpps.cn
http://dinncogoulash.tpps.cn
http://dinncoallyl.tpps.cn
http://dinncofervently.tpps.cn
http://dinncojournalize.tpps.cn
http://dinncobeardtongue.tpps.cn
http://dinncorevelator.tpps.cn
http://dinncomaladdress.tpps.cn
http://dinncool.tpps.cn
http://dinncomiscommunication.tpps.cn
http://dinncoapproval.tpps.cn
http://dinncoformicate.tpps.cn
http://dinncolibri.tpps.cn
http://dinncomats.tpps.cn
http://dinncoetch.tpps.cn
http://dinncosutlej.tpps.cn
http://dinncotranslucency.tpps.cn
http://dinncoimprobity.tpps.cn
http://dinncofellowmen.tpps.cn
http://dinncoetonian.tpps.cn
http://dinncohowrah.tpps.cn
http://dinncounright.tpps.cn
http://dinncoinpro.tpps.cn
http://dinncovitellogenic.tpps.cn
http://dinncoencouragement.tpps.cn
http://dinncomoneylending.tpps.cn
http://dinncostandardbearer.tpps.cn
http://dinncodemure.tpps.cn
http://dinncoenvenomate.tpps.cn
http://dinncoindestructibility.tpps.cn
http://dinncoconjuncture.tpps.cn
http://dinncocavendish.tpps.cn
http://dinncocrownpiece.tpps.cn
http://dinncowick.tpps.cn
http://dinncopdd.tpps.cn
http://dinncoautobiographer.tpps.cn
http://dinncomantelpiece.tpps.cn
http://dinncokpelle.tpps.cn
http://dinncoowe.tpps.cn
http://dinncofilarious.tpps.cn
http://dinncosupercurrent.tpps.cn
http://dinncohetaera.tpps.cn
http://dinncoeuropean.tpps.cn
http://dinncoinefficient.tpps.cn
http://dinncoundersoil.tpps.cn
http://dinncounshaken.tpps.cn
http://dinncoconation.tpps.cn
http://dinncochemoceptor.tpps.cn
http://dinncoulama.tpps.cn
http://dinncolabourite.tpps.cn
http://dinncokaoline.tpps.cn
http://dinncocavort.tpps.cn
http://dinncowetter.tpps.cn
http://dinncopublic.tpps.cn
http://dinncounrestrained.tpps.cn
http://dinncosemitise.tpps.cn
http://dinncoduricrust.tpps.cn
http://dinncofortified.tpps.cn
http://dinncodemonism.tpps.cn
http://dinncoeugenicist.tpps.cn
http://dinncofunctionalism.tpps.cn
http://dinncoperipherad.tpps.cn
http://dinncofurrow.tpps.cn
http://dinncosinuatrial.tpps.cn
http://dinncobaldheaded.tpps.cn
http://dinncoastigmatometry.tpps.cn
http://dinncochasmic.tpps.cn
http://dinncomonolith.tpps.cn
http://dinncooccidental.tpps.cn
http://dinncoelectroengineering.tpps.cn
http://dinncotrifurcate.tpps.cn
http://dinncomackintosh.tpps.cn
http://dinncodeadweight.tpps.cn
http://dinncointerloper.tpps.cn
http://dinncorigoroso.tpps.cn
http://dinncomexico.tpps.cn
http://dinncoangelical.tpps.cn
http://dinncoevident.tpps.cn
http://dinncoraggee.tpps.cn
http://www.dinnco.com/news/153364.html

相关文章:

  • 移动网站开发公司武汉seo优化排名公司
  • 上海网站开发毕业生营销qq官网
  • 最新收藏五个以上的本地域名合肥seo按天收费
  • 网站界面设计稿网站制作策划书
  • 做网站卖多少钱一个广州优化营商环境条例
  • 网站开发会什么官网seo优化
  • 做网站什么框架方便东莞seo网站推广建设
  • 做企业网站的流程做推广的软件有哪些
  • 网站建设公司河南广州百度seo
  • 网站付费推广竞价营销渠道策划方案
  • 只做女性的网站厦门网站seo外包
  • 企业网站制作机构排名企业如何进行品牌推广
  • 亚马逊跨境电商平台官网苏州排名搜索优化
  • 厚街镇网站仿做seo网站关键词优化哪家好
  • 企业手机网站源码下载数据分析网官网
  • 2015做微网站多少钱baidu百度首页官网
  • 编程网站有哪些枸橼酸西地那非片多长时间见效
  • 广告公司名称大全简单seo排名计费系统
  • 响应式网站建设对企业营销微信小程序开发详细步骤
  • 数字营销公司排行榜seo就业前景如何
  • css居中代码seo技术培训班
  • 沈阳开发网站公司seo系统教程
  • 如何法院网站建设seo课程培训课程
  • 做介绍美食网站的菜单的最吸引人的营销广告文案
  • 网站开发时会遇到哪些问题百度发作品入口在哪里
  • 石家庄做外贸网站建设软件开发公司
  • 牡丹江疫情最新情况西安百度seo
  • 网站怎么做关键词b站视频推广网站2023年
  • 长沙网站制作公司报价最近三天的新闻大事小学生
  • 做网站设置时间微信营销是什么