当前位置:网站首页>【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++)
边栏推荐
- parker比例溢流阀RS10R35S4SN1JW
- More than 20million videos have been played in the business list! Why is the reform of Agricultural Academies urged repeatedly?
- JS Es5 can also create constants?
- TCP Socket与TCP 连接
- “推广+搞笑剧情”,如何碰撞出爆款的火花?
- Compile u-boot source code for stm32p157 development board
- 巩固入门-C#基础变量和常量
- Restartprocessifvisible process
- Pref usage record
- 【JVM】一文带你了解JVM中的垃圾回收机制(GC)——内含图解
猜你喜欢

八大基本排序(详解)

restartProcessIfVisible的流程

Implementation of aut, a self-developed transport layer protocol for sound network -- dev for dev column

登录框Tricks

Multi terminal collaboration of Huawei accounts to create a better internet life

Cesium-1.72 learning (eagle eye map of the earth)

Dart: string replace related methods

Mathematical modeling for war preparation 35 time series prediction model

基于SSM实现毕业设计管理系统

Etcd tutorial - Chapter 8 compact, watch, and lease APIs for etcd
随机推荐
Sub chain cross technology source level exploration: an overview of xcvm
阿里云盘分享压缩包
addmodule_allmerge_ams_im
Go micro tutorial - Chapter 1 getting started
List becomes vector list becomes vector list vector
Etcd tutorial - Chapter 8 compact, watch, and lease APIs for etcd
Substrate 跨链技术源码级探索: XCVM的概览
[wechat applet] basic use of common components (view/scroll-view/wiper, text/rich-text, button/image)
Redis elimination strategy
List becomes vector list becomes vector list vector
Exercise book of introduction to database system
[activity registration] it's your turn to explore the yuan universe! I will be waiting for you in Shenzhen on July 2!
[Verilog basics] octal and hexadecimal representation of decimal negative numbers
列表变成向量 列表变向量 list vector
Pref usage record
dart:字符串replace相关的方法
Internet R & D efficiency practice qunar core field Devops landing practice
Cesium-1.72 learning (China national boundary)
RTP sending PS stream zero copy scheme
"Promotion + funny plot", how to collide with the sparks of popular funds?