当前位置:网站首页>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
边栏推荐
- Don't you know the relationship between JSP and servlet?
- leetcode
- 函数重入、函数重载、函数重写自己理解
- “零售为王”下的家电产业:什么是行业共识?
- 2022年信息安全工程师考试大纲
- HDU 4337 King Arthur' S Knights it outputs a Hamiltonian circuit
- Significance and measures of source code confidentiality
- 数学归纳与递归
- Numpy中排序操作partition,argpartition,sort,argsort
- cocos3——8. Implementation Guide for beginners
猜你喜欢
亚像素级角点检测Opencv-cornerSubPix
Create applet from 0
Make (convert) ICO Icon
上个厕所的功夫,就把定时任务的三种调度策略说得明明白白
Analysis of USB network card sending and receiving data
变量、流程控制与游标(MySQL)
Starting from 1.5, build a micro Service Framework -- log tracking traceid
Laravel php artisan 自动生成Model+Migrate+Controller 命令大全
Jericho is in non Bluetooth mode. Do not jump back to Bluetooth mode when connecting the mobile phone [chapter]
leetcode
随机推荐
VHDL实现任意大小矩阵乘法运算
Oracle connection pool is not used for a long time, and the connection fails
mos管實現主副電源自動切換電路,並且“零”壓降,靜態電流20uA
SQL Tuning Advisor一个错误ORA-00600: internal error code, arguments: [kesqsMakeBindValue:obj]
Another million qubits! Israel optical quantum start-up company completed $15million financing
Starting from 1.5, build a micro Service Framework -- log tracking traceid
How to find file accessed / created just feed minutes ago
腾讯云原生数据库TDSQL-C入选信通院《云原生产品目录》
「小样本深度学习图像识别」最新2022综述
从0开始创建小程序
Intelligent static presence detection scheme, 5.8G radar sensing technology, human presence inductive radar application
How to replace the backbone of the model
硬件之OC、OD、推挽解释
Laravel php artisan 自动生成Model+Migrate+Controller 命令大全
CVPR 2022 best paper candidate | pip: six inertial sensors realize whole body dynamic capture and force estimation
Household appliance industry under the "retail is king": what is the industry consensus?
Lingyun going to sea | yidiantianxia & Huawei cloud: promoting the globalization of Chinese e-commerce enterprise brands
密码学系列之:在线证书状态协议OCSP详解
树莓派设置静态ip
Create applet from 0