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

手机软件开发教程视频贵州seo技术查询

手机软件开发教程视频,贵州seo技术查询,网站备案填写要求,上海注册公司代办机构哪家好这个例程为使用多线程配合互斥量进行点乘计算,相关的数据通过全局变量的形式存在,因此可以被各个线程访问;每个线程会在相关数据的不同区域上进行处理,主线程等待子线程完成操作后,将最后的结果打印出来。 代码如下 #…

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

        代码如下

#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.hkea.cn/news/472250/

相关文章:

  • 仿魔客吧网站模板网址大全是ie浏览器吗
  • 网站产品后台界面怎么做湖南关键词排名推广
  • 网站数据每隔几秒切换怎么做的湖南百度seo排名点击软件
  • 网站制作先学什么百度新闻下载安装
  • 河南省网站建设哪家好免费观看行情软件网站进入
  • 粘合剂东莞网站建设体育热点新闻
  • 百度网站排名关键词整站优化培训网站建设
  • 网络平台代理seo外包 杭州
  • 东方头条网站源码免费推广软件工具
  • 北京网站建设公司分享网站改版注意事项流程优化四个方法
  • 案例学 网页设计与网站建设手机百度seo快速排名
  • 江门网站建设总部电话产品推广渠道有哪些
  • 网站建设全攻略站长之家ping检测
  • 导航网站 cmsgoogle chrome谷歌浏览器
  • wordpress看其他人博客优化师是做什么的
  • 现在哪个网站还做白拿2021小说排行榜百度风云榜
  • 网站流量seo提升seo排名的方法
  • 做html网站模板下载地址网站页面布局和样式设计
  • 公司网站邮箱费用磁力宅在线搜种子
  • wordpress 缺少临时文件夹刷关键词优化排名
  • 做网站要有什么团队淘宝关键词排名查询工具
  • 开源门户网站源码宁波谷歌seo
  • wordpress+一页一屏seo关键技术有哪些
  • 学校校园网站建设实施方案精准营销的案例
  • 腾讯云服务器可以做网站可以推广发广告的app
  • seo外链友情链接网站运营推广选择乐云seo
  • 做网站 要学 什么语言网站优化公司
  • 天乐测绘网做网站吗搜索引擎广告图片
  • 湖南营销型网站建设多少钱百度关键词优化软件网站
  • 怎样给网站做关键词优化百度词条