当前位置:网站首页>【C语言】详解线程 — 多线程进行协同运算
【C语言】详解线程 — 多线程进行协同运算
2022-06-30 15:50:00 【嵌入式职场】
目录
1、问题
求和问题,一个子线程计算 1 + ... + 499 的值,另一个线程计算 500 + ... + 1000 的值,最后二者的和相加,即得到 1 + ... + 1000 的值。
2、问题求解
#include <stdio.h>
#include <pthread.h>
int sum_1 = 0;
int sum_2 = 0;
// 线程执行的函数
void* myFunc_1(void* args)
{
for(int i = 1; i < 500; i++)
{
sum_1 = sum_1 + i;
}
}
// 线程执行的函数
void* myFunc_2(void* args)
{
for(int i = 500; i <= 1000; i++)
边栏推荐
- 登录框Tricks
- Redis data structure analysis
- 名单揭晓 | 2021年度中国杰出知识产权服务团队
- How to connect the Internet Reading Notes - Summary
- geo 读取单细胞csv表达矩阵 单细胞 改列名 seurat
- 泰山OFFICE技术讲座:同一行不同字号的字如何对齐绘制
- List becomes vector list becomes vector list vector
- List becomes vector list becomes vector list vector
- 将 EMQX Cloud 数据通过公网桥接到 AWS IoT
- 列表变成向量 列表变向量 list vector
猜你喜欢

Required plug-ins for idea

SSH tool pyqt

声网自研传输层协议 AUT 的落地实践丨Dev for Dev 专栏

24: Chapter 3: develop pass service: 7: user defined exceptions (to represent errors in the program); Create graceexceptionhandler to handle exceptions globally and uniformly (build JSON data of corre

Property or method “approval1“ is not defined on the instance but referenced during render

MC Instruction Decoder
![[activity registration] it's your turn to explore the yuan universe! I will be waiting for you in Shenzhen on July 2!](/img/cf/6fc5f7cafbdc5e165eb119b9b41cd9.jpg)
[activity registration] it's your turn to explore the yuan universe! I will be waiting for you in Shenzhen on July 2!

Etcd教程 — 第九章 Etcd之实现分布式锁

期未课程设计:基于SSM的产品销售管理系统

名单揭晓 | 2021年度中国杰出知识产权服务团队
随机推荐
[Demo] 循环写文件
Geo read single cell CSV expression matrix single cell column name change Seurat
The meaning of linetypes enumeration values (line_4, line_8, line_aa) in opencv
声网自研传输层协议 AUT 的落地实践丨Dev for Dev 专栏
商单视频播放超2000万!农院改造为何屡被催更?
Mathematical modeling for war preparation 34-bp neural network prediction 2
AcWing 第 57 场周赛
Simpleitk encountered an ITK only supports orthonormal direction cosines error while reading NII
Go micro tutorial - Chapter 1 getting started
Mathematical modeling for war preparation 33- grey prediction model 2
Raft introduction
[Verilog basics] octal and hexadecimal representation of decimal negative numbers
3D图表有效提升数据大屏档次
商鼎云新版来袭 | 收藏夹功能已上线,满足个人使用需求
聊聊遠程辦公那些事兒 | 社區征文
巩固入门-C#基础变量和常量
Alibaba cloud disk sharing compressed package
将 EMQX Cloud 数据通过公网桥接到 AWS IoT
idea必用插件
NielsenIQ迎来零售实验室负责人Dawn E. Norvell,将加速扩张全球零售战略