当前位置:网站首页>[C language] detailed explanation of threads - multi threads for collaborative operation
[C language] detailed explanation of threads - multi threads for collaborative operation
2022-06-30 17:14:00 【Embedded workplace】
Catalog
1、 problem
Summation problem , A child thread calculation 1 + ... + 499 Value , Another thread calculates 500 + ... + 1000 Value , The sum of the last two is added , Or get 1 + ... + 1000 Value .
2、 problem solving
#include <stdio.h>
#include <pthread.h>
int sum_1 = 0;
int sum_2 = 0;
// Functions executed by threads
void* myFunc_1(void* args)
{
for(int i = 1; i < 500; i++)
{
sum_1 = sum_1 + i;
}
}
// Functions executed by threads
void* myFunc_2(void* args)
{
for(int i = 500; i <= 1000; i++)
边栏推荐
- [Demo] 循环写文件
- js 从原型链到继承
- Pref usage record
- 商鼎雲新版來襲 | 收藏夾功能已上線,滿足個人使用需求
- unity粒子_异常显示处理
- 平面相交与平面方程
- Property or method “approval1“ is not defined on the instance but referenced during render
- 基于SSM实现毕业设计管理系统
- Jspreadsheet/ce JExcel: more data fields than the given fields (columns) will lead to blank columns. Solution
- Eight basic sorting (detailed explanation)
猜你喜欢

面试突击60:什么情况会导致 MySQL 索引失效?

解决方法:STM32使用cJSON解析数据失败

Redis data structure analysis

HMS core audio editing service 3D audio technology helps create an immersive auditory feast

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

ROC-RK3566-PC使用10.1寸IPS触摸屏显示

Cesium-1.72 learning (camera tracking)

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

The 25th anniversary of Hong Kong's return to China the Hong Kong Palace Museum officially opened as a new cultural landmark

商鼎雲新版來襲 | 收藏夾功能已上線,滿足個人使用需求
随机推荐
leetcode:787. K 站中转内最便宜的航班【k步最短路 + dfs记忆化 + defaultdict(dict)】
nodejs学习笔记二
Property or method “approval1“ is not defined on the instance but referenced during render
高等数学(第七版)同济大学 总习题一 个人解答
The meaning of linetypes enumeration values (line_4, line_8, line_aa) in opencv
Pref usage record
Design of piece counter based on 51 single chip microcomputer
IndexSearch
addmodule_ allmerge_ ams_ im
浅析搭建高速公路视频监控平台的建设方案及必要性
List becomes vector list becomes vector list vector
[JVM] class loading related interview questions - class loading process and parental delegation model
Php7.3 centos7.9 installing sqlserver extensions
几个跨端开发神器
Ningx 1.20.2
[wechat applet] the hosting environment of the applet
Etcd教程 — 第八章 Etcd之Compact、Watch和Lease API
每日刷题记录 (九)
美国PARKER派克传感器P8S-GRFLX
[untitled] write a student achievement and information management system in C language to realize the operation interface, clear screen display of current operation functions, reading and inputting st