Recommended Methods for Re-Entering Code in C, C ++

I read the re-entrancy guide about recommended practices when writing re-entry code.

What other links and resources cover this topic?

What lens-like tools can be used to test these problems?

+7
c ++ c reentrancy
source share
4 answers

A guide is enough.

My personal rule is just 2 for re-entering the code again:

  • accept only transmission parameters by values, only values โ€‹โ€‹transferred as parameters in the function are used.

  • if I need to use any global parameters or pointer (for performance or storage), use a mutex or semaphore to control access to it.

0
source share

Not. Writing code without re-entering is usually more difficult than re-connecting. Just follow these simple rules and donโ€™t try to do anything too shaky and everything will be fine with you.

Code without re-entry is usually written for high-performance problems.

+1
source share
  • Use local variables.
  • Do not use static locales or global variables, even TLS will not help you with recursion / reinstall.
  • Restore all your invariants before making callbacks.
  • Do not hold locks during callbacks. If you absolutely need to (and I will still look for a way to avoid this), then make sure that you know what will happen if you try to re-enter your lock into a thread that already holds it. At a minimum, you need to check this, otherwise depending on the lock, you will get deadlocks or broken invariants (i.e. Corruption).
+1
source share
  • The return function cannot use variables in a non-atomic way if they are not stored on the stack of the calling task or are private variables of this task.
  • A repeated function cannot call other functions that are not reentrant.
  • The return function cannot use the hardware in a non-atomic way.

Ref: Page 462 [INTRODUCTION USING THE RENESAS RX62N MICROCONTROLLER] [James M. Conrad]

0
source share

All Articles