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

aspx网站做app百度推广官方投诉电话

aspx网站做app,百度推广官方投诉电话,wordpress子页面怎么修改,网站首页图片大全这个例程为使用多线程配合互斥量进行点乘计算,相关的数据通过全局变量的形式存在,因此可以被各个线程访问;每个线程会在相关数据的不同区域上进行处理,主线程等待子线程完成操作后,将最后的结果打印出来。 代码如下 #…

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

        代码如下

#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://www.zhongyajixie.com/news/18550.html

相关文章:

  • 黄冈网站制作如何做网络营销推广
  • 个人网站教程aso优化工具
  • wordpress视屏东莞整站优化
  • python做网站好用吗山东seo百度推广
  • 温州网站建设 首选国鼎网络好网页设计模板图片
  • app网站开发多少钱百度推广助手怎么用
  • 深圳市住房和建设局官方网站查询游戏合作渠道
  • 中国交通建设监理协网站福建seo快速排名优化
  • 做企业网站怎么选操作系统神马网站快速排名软件
  • wordpress实时聊天seo优化推广工程师招聘
  • 做电池的外贸网站微信营销模式有哪些
  • 贵阳商城网站建设谷歌优化排名公司
  • 什么网站可以做动画搜索引擎优化排名优化培训
  • 企业宣传型网站建设百度sem认证
  • windows+wordpress+mi漯河搜狗关键词优化排名软件
  • jquery网站模板产品软文范例800字
  • 建材网站开发搜索引擎优化到底是优化什么
  • 怎么查那些人输入做网站怎么把网站排名排上去
  • 南通网站建设外包hao123上网从这里开始官方
  • 怎么做网站的自然排名电脑优化设置
  • 江宁网站建设合肥网站排名
  • 网站开发和运行 法律网络营销策略概念
  • 网站开发过程 文档安徽搜索引擎优化seo
  • 可以做用户旅程图的网站营销型网站建设目标
  • 精美企业网站友情链接名词解释
  • 自己做外贸网站能接到单吗百度统计app
  • 怎么建立一个自己的网站自媒体营销方式有哪些
  • 建立读音关键词优化公司靠谱推荐
  • 成都百度公司怎么样seo大牛
  • 哈尔滨做网站设计专业软文发稿平台