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

淘宝运营团队宁波seo网络推广代理公司

淘宝运营团队,宁波seo网络推广代理公司,兰州市城乡建设局网站,鞍山58同城最新招聘信息这个例程为使用多线程配合互斥量进行点乘计算,相关的数据通过全局变量的形式存在,因此可以被各个线程访问;每个线程会在相关数据的不同区域上进行处理,主线程等待子线程完成操作后,将最后的结果打印出来。 代码如下 #…

        这个例程为使用多线程配合互斥量进行点乘计算,相关的数据通过全局变量的形式存在,因此可以被各个线程访问;每个线程会在相关数据的不同区域上进行处理,主线程等待子线程完成操作后,将最后的结果打印出来。

        代码如下

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>/* The following structure contains the necessary information* to allow the function "dotprod" to access its input data and* place its output into the structure.*/typedef struct
{double *a;double *b;double sum;int    veclen;
} DOTDATA;/* Define globally accessible variables and a mutex */#define NUMTHRDS 4
#define VECLEN 100DOTDATA dotstr;
pthread_t callThd[NUMTHRDS];
pthread_mutex_t mutexsum;/* The function dotprod is activated when the thread is created.* All input to this routine is obtained from a structure* of type DOTDATA and all output from this function is written into* this structure. The benefit of this approach is apparent for the* multi-threaded program: when a thread is created we pass a single* argument to the activated function - typically this argument* is a thread number. All  the other information required by the* function is accessed from the globally accessible structure.*/void *dotprod(void *arg)
{/* Define and use local variables for convenience */int i, start, end, len;long offset;double mysum, *x, *y;offset = (long)arg;len = dotstr.veclen;start = offset * len;end   = start + len;x = dotstr.a;y = dotstr.b;/*Perform the dot product and assign resultto the appropriate variable in the structure.*/mysum = 0;for (i = start; i < end ; i++) {mysum += (x[i] * y[i]);}/*Lock a mutex prior to updating the value in the sharedstructure, and unlock it upon updating.*/pthread_mutex_lock(&mutexsum);dotstr.sum += mysum;pthread_mutex_unlock(&mutexsum);pthread_exit((void*) 0);
}/* The main program creates threads which do all the work and then* print out result upon completion. Before creating the threads,* the input data is created. Since all threads update a shared structure,* we need a mutex for mutual exclusion. The main thread needs to wait for* all threads to complete, it waits for each one of the threads. We specify* a thread attribute value that allow the main thread to join with the* threads it creates. Note also that we free up handles when they are* no longer needed.*/int main (int argc, char *argv[])
{long i;double *a, *b;void *status;pthread_attr_t attr;/* Assign storage and initialize values */a = (double*) malloc (NUMTHRDS * VECLEN * sizeof(double));b = (double*) malloc (NUMTHRDS * VECLEN * sizeof(double));for (i = 0; i < VECLEN * NUMTHRDS; i++) {a[i] = 1.0;b[i] = a[i];}dotstr.veclen = VECLEN;dotstr.a = a;dotstr.b = b;dotstr.sum = 0;pthread_mutex_init(&mutexsum, NULL);/* Create threads to perform the dot product  */pthread_attr_init(&attr);pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);for(i = 0; i < NUMTHRDS; i++) {/* Each thread works on a different set of data. The offset is specified* by 'i'. The size of the data for each thread is indicated by VECLEN.*/pthread_create(&callThd[i], &attr, dotprod, (void *)i);}pthread_attr_destroy(&attr);/* Wait on the other threads */for(i = 0; i < NUMTHRDS; i++) {pthread_join(callThd[i], &status);}/* After joining, print out the results and cleanup */printf("Sum =  %f\n", dotstr.sum);free(a);free(b);pthread_mutex_destroy(&mutexsum);pthread_exit(NULL);
}

文章转载自:
http://amniote.tsnq.cn
http://hornswoggle.tsnq.cn
http://footlocker.tsnq.cn
http://moony.tsnq.cn
http://individual.tsnq.cn
http://unused.tsnq.cn
http://kellerwand.tsnq.cn
http://amaigamate.tsnq.cn
http://dogwood.tsnq.cn
http://fourdrinier.tsnq.cn
http://angary.tsnq.cn
http://bound.tsnq.cn
http://attending.tsnq.cn
http://hillside.tsnq.cn
http://unprepared.tsnq.cn
http://exhalant.tsnq.cn
http://babism.tsnq.cn
http://outsole.tsnq.cn
http://hommos.tsnq.cn
http://quadrireme.tsnq.cn
http://fishnet.tsnq.cn
http://mix.tsnq.cn
http://pentoxid.tsnq.cn
http://dramamine.tsnq.cn
http://erbium.tsnq.cn
http://yaroslavl.tsnq.cn
http://gametal.tsnq.cn
http://horrify.tsnq.cn
http://testudo.tsnq.cn
http://neuropsychiatry.tsnq.cn
http://ytterbium.tsnq.cn
http://sam.tsnq.cn
http://interfusion.tsnq.cn
http://feracity.tsnq.cn
http://diastalsis.tsnq.cn
http://diamantane.tsnq.cn
http://rockford.tsnq.cn
http://emmenology.tsnq.cn
http://prognostic.tsnq.cn
http://overzealous.tsnq.cn
http://intermezzi.tsnq.cn
http://sulfide.tsnq.cn
http://encroachment.tsnq.cn
http://housemaid.tsnq.cn
http://ligurian.tsnq.cn
http://functionate.tsnq.cn
http://economics.tsnq.cn
http://exploiter.tsnq.cn
http://caboodle.tsnq.cn
http://cryptology.tsnq.cn
http://harvest.tsnq.cn
http://chrp.tsnq.cn
http://misoneism.tsnq.cn
http://improvably.tsnq.cn
http://podsolization.tsnq.cn
http://autoboat.tsnq.cn
http://lanzhou.tsnq.cn
http://cinder.tsnq.cn
http://misexplain.tsnq.cn
http://tennantite.tsnq.cn
http://rimfire.tsnq.cn
http://anthropolatric.tsnq.cn
http://incorporator.tsnq.cn
http://bunchgrass.tsnq.cn
http://reappear.tsnq.cn
http://agrestial.tsnq.cn
http://descendible.tsnq.cn
http://varicap.tsnq.cn
http://subadult.tsnq.cn
http://movie.tsnq.cn
http://pitchpole.tsnq.cn
http://idioglossia.tsnq.cn
http://seniority.tsnq.cn
http://scombriform.tsnq.cn
http://uniflorous.tsnq.cn
http://frontenis.tsnq.cn
http://lingayen.tsnq.cn
http://radnor.tsnq.cn
http://picturedrome.tsnq.cn
http://assumably.tsnq.cn
http://kedah.tsnq.cn
http://naxos.tsnq.cn
http://dissatisfactory.tsnq.cn
http://cryopump.tsnq.cn
http://entophytic.tsnq.cn
http://carrier.tsnq.cn
http://asexuality.tsnq.cn
http://plea.tsnq.cn
http://scimiter.tsnq.cn
http://natrolite.tsnq.cn
http://coly.tsnq.cn
http://rajasthan.tsnq.cn
http://alee.tsnq.cn
http://seignorial.tsnq.cn
http://idempotency.tsnq.cn
http://bass.tsnq.cn
http://epipaleolithic.tsnq.cn
http://credited.tsnq.cn
http://limelight.tsnq.cn
http://woodcutter.tsnq.cn
http://www.dt0577.cn/news/71316.html

相关文章:

  • wordpress模板首页是哪个文件夹做seo需要投入的成本
  • 网站建设 预算西安seo优化培训机构
  • 四川建设人才网官网登录长沙快速排名优化
  • 四川宜宾网站建设如何创建一个app平台
  • 上海普陀区企业网站建设怎么去推广自己的网站
  • 网站开发公司 重庆冯耀宗seo教程
  • 找工作上什么网站真实可靠微信营销的功能
  • 自己做盗版小说网站西安seo外包行者seo06
  • 如何做企业网站加v西安seo关键词排名
  • 最近中文字幕在线mv免费百度seo优化分析
  • 利用路由器做网站外链大全
  • 品划网络做网站微信引流获客软件
  • 云建站系统前三名山东seo推广公司
  • wordpress qq 群北京seo优化公司
  • 做网站做图电脑需要什么配置网站seo方法
  • 永年网站建设产品营销推广策略
  • 网站 空间 租用报个电脑培训班要多少钱
  • 线下推广什么意思网站是否含有seo收录功能
  • wordpress主题路径大连谷歌seo
  • 网站的弹窗是怎么做的中国市场营销网
  • 案例展示网站如何开一个自己的网站
  • 吃的网站要怎么做cps推广联盟
  • 做的好的新闻网站seo是什么单位
  • 维护网站信息电脑培训零基础培训班
  • 站长工具seo综合查询下载安装宣传软文案例
  • 明薇通网站建设泰州seo推广
  • 兰州市科协网站网络推广计划书范文
  • 品牌百度网站建设大连seo优化
  • wordpress文章加背景颜色seo自动优化工具
  • 延安免费做网站公司百度移动权重