当前位置:网站首页>【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++)
边栏推荐
- Restartprocessifvisible process
- Exception class_ Log frame
- Cesium-1.72 learning (eagle eye map of the earth)
- 定时任务删除指定时间的的数据
- Substrate 跨链技术源码级探索: XCVM的概览
- Lambda表达式_Stream流_File类
- nichenet实战silicosis
- [JVM] takes you to learn about the garbage collection mechanism (GC) in the JVM -- including diagrams
- 编译丨迅为iTOP4412开发板Makefile编译
- Property or method “approval1“ is not defined on the instance but referenced during render
猜你喜欢

List announced - outstanding intellectual property service team in China in 2021

巩固入门-C#基础变量和常量

商鼎云新版来袭 | 收藏夹功能已上线,满足个人使用需求

异常类_日志框架

Nodejs learning notes II

More dragon lizard self-developed features! Production available Anolis OS 8.6 officially released

Mathematical modeling for war preparation 33- grey prediction model 2

Data security compliance has brought new problems to the risk control team

美国PARKER派克传感器P8S-GRFLX

ssh工具 pyqt
随机推荐
How to connect the Internet Reading Notes - Summary
利用PIL进行不失真的resize
List becomes vector list becomes vector list vector
数据库系统概论习题册
Raft introduction
addmodule_ allmerge_ ams_ im
Nut cloud - sync files on your mobile hard drive on your new computer
Pref usage record
山西化工园区智能化管控平台建设时间表
MC Instruction Decoder
声网自研传输层协议 AUT 的落地实践丨Dev for Dev 专栏
Cesium-1.72 learning (camera tracking)
定时任务删除指定时间的的数据
geo 读取单细胞csv表达矩阵 单细胞 改列名 seurat
CGR 21 (D,E,F)
[wechat applet] basic use of common components (view/scroll-view/wiper, text/rich-text, button/image)
Exception class_ Log frame
Etcd tutorial - Chapter 9 etcd implementation of distributed locks
【OpenCV 例程200篇】215. 基于多段线绘制近似椭圆
Delete duplicates in an ordered array ii[double pointers -- unified in multiple cases]