当前位置:网站首页>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
边栏推荐
- 变量、流程控制与游标(MySQL)
- [dream database] add the task of automatically collecting statistical information
- SSL证书错误怎么办?浏览器常见SSL证书报错解决办法
- Shell programming basics
- Development of wireless communication technology, cv5200 long-distance WiFi module, UAV WiFi image transmission application
- 迷失在MySQL的锁世界
- Flink task exit process and failover mechanism
- 杰理之开启经典蓝牙 HID 手机的显示图标为键盘设置【篇】
- 商城商品的知识图谱构建
- SQL中删除数据
猜你喜欢
随机推荐
Room rate system - login optimization
Mathematical induction and recursion
LAB1配置脚本
Jerry's RTC clock development [chapter]
Make (convert) ICO Icon
首届“量子计算+金融科技应用”研讨会在京成功举办
Shangsilicon Valley JVM Chapter 1 class loading subsystem
Numpy中排序操作partition,argpartition,sort,argsort
Analysis of USB network card sending and receiving data
[untitled]
VHDL实现任意大小矩阵乘法运算
Nuggets quantification: obtain data through the history method, and use the same proportional compound weight factor as Sina Finance and snowball. Different from flush
Flutter3.0了,小程序不止于移动应用跨端运行
Stored procedures and functions (MySQL)
Laravel php artisan 自动生成Model+Migrate+Controller 命令大全
树莓派设置wifi自动连接
如何替换模型的骨干网络(backbone)
Simple bubble sort
Intelligent static presence detection scheme, 5.8G radar sensing technology, human presence inductive radar application
掘金量化:通过history方法获取数据,和新浪财经,雪球同用等比复权因子。不同于同花顺








