当前位置:网站首页>【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++)
边栏推荐
猜你喜欢

Raft introduction

Mathematical modeling for war preparation 36 time series model 2

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

每日刷题记录 (九)

基于51单片机的计件器设计

Design of piece counter based on 51 single chip microcomputer

【JVM】类加载相关面试题——类加载过程、双亲委派模型

深度学习——(2)几种常见的损失函数

互联网研发效能实践之去哪儿网(Qunar)核心领域DevOps落地实践

ROC-RK3566-PC使用10.1寸IPS触摸屏显示
随机推荐
addmodule_ allmerge_ ams_ im
leetcode:787. K 站中转内最便宜的航班【k步最短路 + dfs记忆化 + defaultdict(dict)】
[wechat applet] basic use of common components (view/scroll-view/wiper, text/rich-text, button/image)
【JVM】类加载相关面试题——类加载过程、双亲委派模型
RTP sending PS stream zero copy scheme
Supplementary
Property or method “approval1“ is not defined on the instance but referenced during render
Etcd tutorial - Chapter 8 compact, watch, and lease APIs for etcd
HMS core audio editing service 3D audio technology helps create an immersive auditory feast
CGR 21 (D,E,F)
补充材料 supplementary
IO流_递归
Design of piece counter based on 51 single chip microcomputer
Tutoriel etcd - chapitre 8 API compacte, Watch et lease pour etcd
List becomes vector list becomes vector list vector
A scheduled task deletes data at a specified time
"Promotion + funny plot", how to collide with the sparks of popular funds?
Etcd教程 — 第八章 Etcd之Compact、Watch和Lease API
阿里云盘分享压缩包
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