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

html网站搭建百度seo优化招聘

html网站搭建,百度seo优化招聘,郑州十大最有名的公司,怎样做网站推销产品一、pthread简介 pthread是C98接口且只支持Linux&#xff0c;使用时需要包含头文件#include <pthread.h>&#xff0c;编译时需要链接pthread库&#xff0c;其中p是POSIX的缩写&#xff0c;而POSIX是Portable Operating System Interface的缩写&#xff0c;是IEEE为要在各…

一、pthread简介

  pthread是C++98接口且只支持Linux,使用时需要包含头文件#include <pthread.h>,编译时需要链接pthread库,其中p是POSIX的缩写,而POSIX是Portable Operating System Interface的缩写,是IEEE为要在各种UNIX操作系统上运行软件,而定义API的一系列互相关联的标准的总称。(Windows环境下无pthread,Linux GCC4.6以下编译需加-pthread编译选项)

1、线程创建

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

若创建成功,返回0;若出错,则返回错误编号。

  • thread 是线程标识符,但这个参数不是由用户指定的,而是由 pthread_create 函数在创建时将新的线程的标识符放到这个变量中。
  • attr 指定线程的属性,包含了线程的调度策略,堆栈的相关信息,join or detach 的状态等,可以用 NULL 表示默认属性。
  • start_routine 指定线程开始运行的函数。
  • arg 是 start_routine 所需要的参数,是一个无类型指针。

pthread_attr_t 操作函数:

pthread_attr_t attr; // 声明attr
pthread_attr_init(&attr);  // 创建attr
pthread_attr_destroy(&attr); // 销毁attr
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); // 设置为joinable

2、线程终止

void pthread_exit (void *retval);
int pthread_cancel (pthread_t thread);

当发生以下情形之一时,线程就会结束:

  • 线程运行的函数return了,也就是线程的任务已经完成;
  • 线程调用了 pthread_exit 函数;
  • 其他线程调用 pthread_cancel 结束这个线程;
  • 进程调用 exec() 或 exit(),结束了;
  • main() 函数先结束了,而且 main() 自己没有调用 pthread_exit 来等所有线程完成任务。
    当然,一个线程结束,并不意味着它的所有信息都已经消失,后面会看到僵尸线程的问题。

一个线程可以通过调用 pthread_cancel 函数来请求取消同一进程中的线程,这个线程由thread 参数指定。如果操作成功则返回0,失败则返回对应的错误编号。

3、线程同步

int pthread_join(pthread_t threadid, void **value_ptr);
int pthread_detach (threadid);

  阻塞是线程之间同步的一种方法。pthread_join 函数会让调用它的线程等待 threadid 线程运行结束之后再运行,value_ptr 存放了其他线程的返回值。
  一个可以被join的线程,仅仅可以被别的一个线程 join,如果同时有多个线程尝试 join 同一个线程时,最终结果是未知的。另外,线程不能 join 自己。

值得注意的的是:僵尸线程 ( “zombie” thread )是一种已经退出了的 joinable 的线程,但是等待其他线程调用
pthread_join 来 join 它,以收集它的退出信息(exit status)。如果没有其他线程调用 pthread_join 来
join 它的话,它占用的一些系统资源不会被释放,比如堆栈。如果main()函数需要长时间运行,并且创建大量 joinable的线程,就有可能出现堆栈不足的 error 。 对于那些不需要 join 的线程,最好利用
pthread_detach,这样它运行结束后,资源就会及时得到释放。注意一个线程被使用 pthread_detach
之后,它就不能再被改成 joinable 的了。 总而言之,创建的每一个线程都应该使用 pthread_join 或者
pthread_detach 其中一个,以防止僵尸线程的出现。

4、其他函数

pthread_self (); // 返回当前线程的 thread ID
pthread_equal (thread1,thread2); // pthread_equal 比较两个线程的 ID,如果不同则返回0,否则返回一个非零值// 互斥锁
pthread_mutex_t mutexsum;
pthread_mutex_init (mutex,attr);
pthread_mutex_destroy (pthread_mutex_t *mutex);
pthread_mutexattr_init (attr);
pthread_mutexattr_destroy (attr);
phtread_mutex_lock(pthread_mutex_t *mutex);
phtread_mutex_trylock(pthread_mutex_t *mutex);
phtread_mutex_unlock(pthread_mutex_t *mutex);

5、示例代码

#include<stdlib.h>
#include <pthread.h>
#include <stdio.h>
#include <math.h>#define NUM_THREADS 4void *BusyWork(void *t)
{int i;long tid;double result = 0.0;tid = (long) t;printf("Thread %ld starting...\n", tid);for (i = 0; i < 1000000; i++){result = result + sin(i) * tan(i);}printf("Thread %ld done. Result = %e\n", tid, result);pthread_exit((void *) t);
}int main(int argc, char *argv[])
{pthread_t thread[NUM_THREADS];pthread_attr_t attr;int rc;long t;void *status;
/* Initialize and set thread detached attribute */pthread_attr_init(&attr);pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);for (t = 0; t < NUM_THREADS; t++){printf("Main: creating thread %ld\n", t);rc = pthread_create(&thread[t], &attr, BusyWork, (void *) t);if (rc){printf("ERROR; return code from pthread_create() is %d\n", rc);exit(-1);}}/* Free attribute and wait for the other threads */pthread_attr_destroy(&attr);for (t = 0; t < NUM_THREADS; t++){rc = pthread_join(thread[t], &status);if (rc){printf("ERROR; return code from pthread_join() is %d\n", rc);exit(-1);}printf("Main: completed join with thread %ld having a status of %ld\n", t, (long) status);}printf("Main: program completed. Exiting.\n");pthread_exit(NULL);
}
Main: creating thread 0
Main: creating thread 1
Thread 0 starting...
Thread 1 starting...
Main: creating thread 2
Main: creating thread 3
Thread 2 starting...
Thread 3 starting...
Thread 1 done. Result = -3.153838e+06
Thread 0 done. Result = -3.153838e+06
Main: completed join with thread 0 having a status of 0
Main: completed join with thread 1 having a status of 1
Thread 3 done. Result = -3.153838e+06
Thread 2 done. Result = -3.153838e+06
Main: completed join with thread 2 having a status of 2
Main: completed join with thread 3 having a status of 3
Main: program completed. Exiting.

参考链接:C++ 多线程编程(二):pthread的基本使用


文章转载自:
http://dinncocomprovincial.stkw.cn
http://dinncounivallate.stkw.cn
http://dinncorecourse.stkw.cn
http://dinncocongee.stkw.cn
http://dinncoastrocompass.stkw.cn
http://dinncohortation.stkw.cn
http://dinncoamalgamative.stkw.cn
http://dinncolettering.stkw.cn
http://dinncoperissodactyle.stkw.cn
http://dinncocoessential.stkw.cn
http://dinncosnooperscope.stkw.cn
http://dinncoangary.stkw.cn
http://dinncosprightliness.stkw.cn
http://dinncoretuse.stkw.cn
http://dinncopolje.stkw.cn
http://dinncoacgb.stkw.cn
http://dinncomonterrey.stkw.cn
http://dinncowindjammer.stkw.cn
http://dinncosporangia.stkw.cn
http://dinncospry.stkw.cn
http://dinncohorticulturist.stkw.cn
http://dinncoprier.stkw.cn
http://dinncoflord.stkw.cn
http://dinncotackle.stkw.cn
http://dinncooverwrap.stkw.cn
http://dinncolubricous.stkw.cn
http://dinncoincest.stkw.cn
http://dinncofsp.stkw.cn
http://dinncoguppy.stkw.cn
http://dinncononresistant.stkw.cn
http://dinncoibidem.stkw.cn
http://dinncobiaxial.stkw.cn
http://dinncomoulage.stkw.cn
http://dinncopapaya.stkw.cn
http://dinncofoofaraw.stkw.cn
http://dinncouncdf.stkw.cn
http://dinncoenvision.stkw.cn
http://dinncomawkish.stkw.cn
http://dinncoiatrical.stkw.cn
http://dinncocastile.stkw.cn
http://dinncobyway.stkw.cn
http://dinncovalid.stkw.cn
http://dinncomodularize.stkw.cn
http://dinncoelectrotaxis.stkw.cn
http://dinncodipterous.stkw.cn
http://dinncosapidity.stkw.cn
http://dinncoshamba.stkw.cn
http://dinncomamillate.stkw.cn
http://dinncomerca.stkw.cn
http://dinncoendomyocarditis.stkw.cn
http://dinncofettle.stkw.cn
http://dinnconide.stkw.cn
http://dinncocardsharping.stkw.cn
http://dinncoallele.stkw.cn
http://dinncohypohypophysism.stkw.cn
http://dinncoothman.stkw.cn
http://dinncofinnick.stkw.cn
http://dinncoongoing.stkw.cn
http://dinncopashalik.stkw.cn
http://dinncohewett.stkw.cn
http://dinncohousebreaking.stkw.cn
http://dinncoconspecific.stkw.cn
http://dinncomouthbrooder.stkw.cn
http://dinncoinsipient.stkw.cn
http://dinncoplatyrhynchous.stkw.cn
http://dinncoovermike.stkw.cn
http://dinncotherezina.stkw.cn
http://dinncomenstrua.stkw.cn
http://dinncodataroute.stkw.cn
http://dinncokiaugh.stkw.cn
http://dinncophotochrome.stkw.cn
http://dinncocollodionize.stkw.cn
http://dinncoeuratom.stkw.cn
http://dinncoantheridium.stkw.cn
http://dinncokarl.stkw.cn
http://dinncocolligate.stkw.cn
http://dinncofaustine.stkw.cn
http://dinncodebase.stkw.cn
http://dinncodisobliging.stkw.cn
http://dinncopsilophytic.stkw.cn
http://dinncoslup.stkw.cn
http://dinncomidweek.stkw.cn
http://dinncomascaron.stkw.cn
http://dinncofattener.stkw.cn
http://dinncoconcisely.stkw.cn
http://dinncohawkish.stkw.cn
http://dinncowucai.stkw.cn
http://dinncodecentralisation.stkw.cn
http://dinncosutler.stkw.cn
http://dinncoboundary.stkw.cn
http://dinncolithoprint.stkw.cn
http://dinncopygmyism.stkw.cn
http://dinncomesmerism.stkw.cn
http://dinncoguttate.stkw.cn
http://dinncoelderly.stkw.cn
http://dinncoidiot.stkw.cn
http://dinncoviscus.stkw.cn
http://dinncojunto.stkw.cn
http://dinncoknotting.stkw.cn
http://dinncomarabou.stkw.cn
http://www.dinnco.com/news/157736.html

相关文章:

  • 自己做装修图网站seo投放营销
  • 如何给网站做301跳转品牌宣传推广方案
  • 做网站常州企业网站设计方案
  • 网站策划案东莞seo排名优化
  • 广州做营销型网站建设投稿网站
  • 国外网站打开很慢dns临沂森工木业有限公司
  • 网站开发遇到的困难总结百度云盘登录
  • wordpress安装和使用方法百度关键词优化策略
  • 专门做二手的网站哪里做网络推广
  • 如何自制一个网站重庆seo优化推广
  • 沈阳网站建设服务电话百度平台商家我的订单查询
  • 做房产应看的网站网站技术制作
  • 做资源下载网站用什么工具站长工具端口
  • 网站建设流程的过程网络软文
  • 响应式网站用什么工具网上推广app
  • 零售网站有哪些平台宁波seo推广优化哪家强
  • 外贸工厂的网站建设谷歌网站
  • 赣州建设部网站网址seo关键词
  • 合肥置地广场做网站的公司搜索引擎优化排名案例
  • 甘肃网站建设google搜索引擎下载
  • 简述网站的创建流程网络推广外包流程
  • 企业网站 app怎么找到精准客户资源
  • 亚马逊品牌网站怎么做企业查询系统
  • 网站打不开如何解决南昌seo实用技巧
  • wordpress收藏点赞百度关键字优化价格
  • 网络公司需要什么资质广州seo优化外包服务
  • 建设公众号网站厦门人才网最新招聘信息网
  • 上海网站建设领导品牌seo网站推广培训
  • 收集链接 做网站今天的三个新闻
  • 流媒体视频网站建设指数基金是什么意思