ARM Technical Support Knowledge Articles


Applies to: RTX51 Real-time Kernel


Information in this article applies to:


Help. I'm really confused by reentrant function in RTX51. My RTX51 manuals say that reentrant functions only work in the COMPACT memory model. However, many of the library routines are reentrant even in the SMALL and LARGE models.


Frequently, there is confusion over the difference between reentrant functions and functions that are reentrant. There are two distinct meanings of the word reentrant.

In C51, you may declare functions using the reentrant keyword. For example:

int function (int a, int b, int c) compact reentrant
long x, y, z;

This is a reentrant function that is declared using the reentrant keyword. The arguments (a, b, and c) and local variables (x, y, and z) are stored on a simulated stack in PDATA (the COMPACT memory model).

If we did not specify COMPACT in the function declaration, the arguments and local variables would be stored in DATA, PDATA, or XDATA memory (depending on the default memory model -- SMALL, COMPACT, or LARGE).

These functions are called reentrant functions.

There are functions that, by their nature, are reentrant. These functions use only registers for arguments and local variables and are typically written in assembly. Many of the library routines in the C51 library are written this way. They are, therefore, functions that are reentrant, but they are not declared using the reentrant keyword.

These functions are simply functions that are reentrant.

In RTX51, you may only use the SMALL or LARGE memory model. The COMPACT memory model is not allowed for normal functions. It is REQUIRED, however, for reentrant functions.

If you invoke library routines from multiple tasks, you must ensure that they can be re-entered. That means that either A) these routines only use registers (and are marked in the library section of the manual as functions that are reentrant) or B) you protect the non-reentrant routines with a semaphore. A library call that is included in a reentrant function is NOT reentrant.

Routines that you write and call from multiple tasks must either A) be declared as reentrant functions like example 1 above using the COMPACT memory model (because that's all that RTX51 supports for reentrant functions), or B) be reentrant by nature by only using registers and not any fixed memory locations.


Article last edited on: 2005-07-09 10:59:53

Rate this article

Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential