C、C++ 中可重入代码的推荐做法
I was going through a re-entrancy guide on recommended practices when writing re-entrant code.
What other references and resources cover this topic?
What lint-like tools can be used to check for these issues?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
真的没有。编写不可重新输入的代码通常比可重新输入的代码更困难。只要遵循这些简单的指导方针,不要尝试做任何太清醒的事情,你就会没事的。
不可重入代码通常是为了高性能问题而编写的。
None really. Writting non-reentering code is usually more difficult than re-entring. Just follow those simple guidelines and don't try to do anything too waky and you'll be fine.
Non-reentering code is usually written for high-performance issues.
指南就足够了。
对于重新输入代码,我个人的经验法则只有 2 个:
仅采用值参数传递,仅使用作为函数中参数传入的值。
如果我需要使用任何全局参数或指针(出于性能或存储考虑),请使用互斥体或信号量来控制对其的访问。
The guide is sufficient.
My personal rule of thumbs are only 2 for re-reentering code:
take only pass by value parameters, used only value passed in as parameters in the function.
if I need to use any global parameters or pointer (for performance or storage sake), use a mutex or semaphore to control access to it.
存储在调用任务的堆栈上或者是该任务的私有变量。
参考:第 462 页 [使用介绍
瑞萨 RX62N 微控制器] [James M. Conrad]
stored on the stack of the calling task or are the private variables of that task.
Ref: Page 462 [AN INTRODUCTION USING THE
RENESAS RX62N MICROCONTROLLER] [James M. Conrad]