当前位置:网站首页>Function reentry, function overloading and function rewriting are understood by yourself
Function reentry, function overloading and function rewriting are understood by yourself
2022-07-07 03:23:00 【QQ851301776】
Created by QQ:851301776, mailbox :[email protected], Welcome to technical exchange , This blog is mainly my own learning experience , Just to make a little progress every day !
Personal motto :
1. No one was born , As long as it is thick, it will happen .
2. You can have a low degree , You can skip school , But you have to learn
One 、 Function reentry
In the process of real-time system design , There will be multiple tasks ( Threads ) Calling the same function . If multiple tasks call this function at the same time , It is possible to modify data in other tasks , Thus leading to unforeseen consequences . This function is not safe , Also called non reentrant function .
contrary , Reentrant function means that it can be called by multiple tasks at the same time , There is no need to worry about whether the data will go wrong during the call . A reentrant function is simply Functions that can be interrupted (CPU Save register information to stack , Jump to the interrupt position and load the instruction into the register for execution , After execution , Go back and continue ), in other words , You can interrupt this function at any time it executes , into OS Schedule to execute another piece of code , And nothing goes wrong when you return to control ; and
Non reentrant functions use some system resources , such as Global variable area , Interrupt vector table etc. , So if it's interrupted , There may be problems , This kind of function can't run in multitasking environment .
When writing reentrant functions , If global variables are used , It should be interrupted by closing 、 When the semaphore is received, add one protection .
explain : If the global variables used are not protected , Then this function is not reentrant , When multiple processes call this function , It is very possible to make the relevant global variables become Unknowable state .
The way to guarantee the reentrancy of functions :
- Try to use local variables when writing functions , Don't use global variables .
- Do not use static data structures , Static data structure , Extends the life cycle of variables , Make right value ( Constant ) Change to lvalue ( Variable ).
- Do not call standard I/O function ( Not thread safe )
- Don't use malloc and free( It's thread safe , But don't re-enter )
Linux Common reentrant functions
Two 、 Function rewriting
First rewrite in C++ Inheritance is used more .
If you declare a member function in the base class as a virtual function , Then the member function with the same prototype as the function in the subclass is also a virtual function , And the version in the base class is overwritten , That is, function rewriting .
3、 ... and 、 function overloading
C++ The concept of ,C Language does not involve overloading
In the same scope , Define a function with the same name , But their parameters must be distinguished , Such a function will constitute an overloaded relationship
More than three functions , Constitute heavy load
May refer to : Review the old and learn the new (C++)_QQ851301776 The blog of -CSDN Blog
边栏推荐
- 知识图谱构建全流程
- How to replace the backbone of the model
- 编译常量、ClassLoader类、系统类加载器深度探析
- [tools] basic concept of database and MySQL installation
- Household appliance industry under the "retail is king": what is the industry consensus?
- Le tube MOS réalise le circuit de commutation automatique de l'alimentation principale et de l'alimentation auxiliaire, et la chute de tension "zéro", courant statique 20ua
- Jerry's FM mode mono or stereo selection setting [chapter]
- 【基于 RT-Thread Studio的CPK-RA6M4 开发板环境搭建】
- 线性表的查找
- How-PIL-to-Tensor
猜你喜欢
Flink task exit process and failover mechanism
商城商品的知识图谱构建
The latest 2022 review of "small sample deep learning image recognition"
The whole process of knowledge map construction
又一百万量子比特!以色列光量子初创公司完成1500万美元融资
“去虚向实”大潮下,百度智能云向实而生
The first symposium on "quantum computing + application of financial technology" was successfully held in Beijing
mos管實現主副電源自動切換電路,並且“零”壓降,靜態電流20uA
Not All Points Are Equal Learning Highly Efficient Point-based Detectors for 3D LiDAR Point
Flutter3.0了,小程序不止于移动应用跨端运行
随机推荐
Lavel PHP artisan automatically generates a complete set of model+migrate+controller commands
Jerry's ble exiting Bluetooth mode card machine [chapter]
Cocos2d-x box2d physical engine compilation settings
HDU ACM 4578 Transformation->段树-间隔的变化
【Swift】学习笔记(一)——熟知 基础数据类型,编码风格,元组,主张
Matlab Error (Matrix dimensions must agree)
图形化工具打包YOLOv5,生成可执行文件EXE
oracle连接池长时间不使用连接失效问题
上个厕所的功夫,就把定时任务的三种调度策略说得明明白白
What about SSL certificate errors? Solutions to common SSL certificate errors in browsers
leetcode-02(链表题)
Intelligent static presence detection scheme, 5.8G radar sensing technology, human presence inductive radar application
Another million qubits! Israel optical quantum start-up company completed $15million financing
2022.6.28
unrecognized selector sent to instance 0x10b34e810
netperf 而网络性能测量
校招行测笔试-数量关系
Install torch 0.4.1
Codeforces round 264 (Div. 2) C gargari and Bishop [violence]
centerX: 用中国特色社会主义的方式打开centernet