[TriLUG] shared libraries aren't shared

Aaron Schrab aaron at schrab.com
Wed Nov 11 18:51:19 EST 2009


At 13:36 -0800 11 Nov 2009, Joseph Mack NA3T <jmack at wm7d.net> wrote:
> On Wed, 11 Nov 2009, Alan Porter wrote:
>
>>
>> That is not how shared libraries work (thank goodness).
>
> did they used to work this way?

Global variables in shared libraries have always worked how they do now.  
A good example of this is the standard "errno" variable that is set by 
many functions in libc.  If that were ever shared across processes it 
would have been immediately obvious that is was a horrible interface, 
rather than taking a few years for that conclusion to become commonly 
accepted.

> So shared globals in libraries is process safe, but not thread safe?

Yes.

> I still don't get a race condition when used by two executables. Is 
> the static int j stored in its own data segment too?

As far as the OS is concerned static variables are handled similarly to 
globals, both exist at the same location in memory for the duration of 
the program.  But with static variables, the compiler limits the scope 
in which the variable name can be used to refer to that location.



More information about the TriLUG mailing list