How to make a C code reentrant?

Dear reader,

This is a query related to multiuser environment. I have a piece of code written in C. Now I want to make this code as reentrant and execute on several trminals at the same time, such that there exists only one copy of code in the memory.

Please tell me..

  1. What are the parameters required to make a code reentrant?
  2. Can we use the same parameters on a linux environment?

Thanking you,

Neelam,
I suggest that to be on the safer side on a networking environment, only use those system calls that are reentrant as specified by Posix. Before using any System Canl, just refer the manual on the machine to find if it adheres to those standards.

And unluckily if u have to use a Call that is non- reentrant.. i.e mainly the Blocking or Slow system call, then better check the return values of the call while calling them and if its a failure then better restart the System Call to proceed ahead or your system can behave in really amazing ways.

Good Luck.. :slight_smile:

Did you write the code?
Was it written for and compiled on UNIX/Linux?
Does the code interact with any devices or shared resources?

In general (based on your question alone), you can run a
"black box" type of process any number of times from any
number of termials. Much depends on what it is the code
needs to do.
The basics for writing reentrant functions is
a reentrant function does not hold static data over successive
calls, nor does it return a pointer to static data. All data is
provided by the caller of the function. A reentrant function must
not call non-reentrant functions.
In most cases, non-reentrant functions must be replaced by
functions with a modified interface to be reentrant. Non-reentrant
functions cannot be used by multiple threads. Furthermore, it may
be impossible to make a non-reentrant function thread-safe.

You may want to pick up a book or two on advanced unix
programming and programming threads for a more in-depth
discussion on reentrant and thread-safe code.