[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: reentrantcy?



On Saturday, November 19, 2011 07:27:14 PM you wrote:
> On Sat, Nov 19, 2011 at 07:03:19PM -0600, Paul Elliott wrote:
> > Is there any requirement that a shared library be reentrant, if the
> > upstream wrote it that way?
> > 
> > Am I correct in my assumption, that although non-reentrancy presents a
> > problem for multi threaded programs, it is not a problem for
> > multi-programming, that is two programs using the same shared library at
> > the same time, because the linker will assure that the separate programs
> > will have separate copies of any writable global or static data?
> 

A
> It's not the linker that does it, it's the kernel. Separate programs
> have separate address space and can not influence each other over memory
> unless they make the effort of setting up shared memory.
> 
> > I believe that it is better to write reentrant code and such code should
> > be written when starting from scratch. But there is no reason not to use
> > already existing non-reentrant code in non multi threaded applications.
> > Am I correct?
> 
> There is also the case that a library can be used more than once without
> threads, for example when you use the library in your program and
> another library you link in also links to that library.
>
B 
> If all linkings are shared, it is my understanding that the global state
> of the multiple-linked library would be shared by all references.

Statement A and B above seem to contradict each other.

If global state means global variables, my experiments show that B is not true 
but A is true.

The state of a global variable in one program does not effect the state of the 
same global variable in another program that links the same shared library. 
Both programs have seperate copies of static or global writable varriables of 
the shared library.
Unless the programmer takes special action to force only one copy.

Best Wishes.

-- 
Paul Elliott                               1(512)837-1096
pelliott@BlackPatchPanel.com               PMB 181, 11900 Metric Blvd Suite J
http://www.free.blackpatchpanel.com/pme/   Austin TX 78758-3117

Attachment: signature.asc
Description: This is a digitally signed message part.


Reply to: