当前位置:网站首页>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

你知道电子招标最突出的5大好处有哪些吗?

上个厕所的功夫,就把定时任务的三种调度策略说得明明白白

CVPR 2022 最佳论文候选 | PIP: 6个惯性传感器实现全身动捕和受力估计

Household appliance industry under the "retail is king": what is the industry consensus?

“零售为王”下的家电产业:什么是行业共识?

Create applet from 0

Construction of knowledge map of mall commodities

从0开始创建小程序

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
随机推荐
New benchmark! Intelligent social governance
Optimization of application startup speed
Appx code signing Guide
LAB1配置脚本
如何替换模型的骨干网络(backbone)
Development of wireless communication technology, cv5200 long-distance WiFi module, UAV WiFi image transmission application
CVPR 2022 best paper candidate | pip: six inertial sensors realize whole body dynamic capture and force estimation
【无标题】
VHDL实现任意大小矩阵乘法运算
CVPR 2022 最佳论文候选 | PIP: 6个惯性传感器实现全身动捕和受力估计
Mathematical induction and recursion
HDU ACM 4578 Transformation->段树-间隔的变化
Analysis of USB network card sending and receiving data
源代码保密的意义和措施
Jericho turns on the display icon of the classic Bluetooth hid mobile phone to set the keyboard [chapter]
leetcode
Household appliance industry under the "retail is king": what is the industry consensus?
线性表的查找
知识图谱构建全流程
Cryptography series: detailed explanation of online certificate status protocol OCSP