Shared libraries and thread/process affinity?
Posted: Sat May 14, 2011 1:33 pm
Good evening.
How does a shared library handle the fact of many threads and processes are accessing it at one?
The full story, including how i understood a concept of a shared library:
A shared library implement some functions that the applications use. It is located in a common address space and is accessed by calling the required subroutines (with addresses provided to application by the loader/linker). It also have some internal state, like tracking which processes use which of whatever resource it provides.
Now, there is a problem - what would happen if there is a bug or an exception in the library? The kernel would not know that, sending the signal to the process that called the lib, triggering it's response or death and leaving the lib in inconsistent state and/or unable to handle exceptions.
So, how is this usually handled?
I tried to direct the calls thru a linker-made gates, that would track the change of affinity, but that had cumulative effects of breaking other things, which had to be fixed, etc, etc...
Eventually everything worked out perfectly, but stepping back i see an intricate (but rugged) Rube Goldberg machine, which gets me here with a question - how is it handled properly/usually?
How does a shared library handle the fact of many threads and processes are accessing it at one?
The full story, including how i understood a concept of a shared library:
A shared library implement some functions that the applications use. It is located in a common address space and is accessed by calling the required subroutines (with addresses provided to application by the loader/linker). It also have some internal state, like tracking which processes use which of whatever resource it provides.
Now, there is a problem - what would happen if there is a bug or an exception in the library? The kernel would not know that, sending the signal to the process that called the lib, triggering it's response or death and leaving the lib in inconsistent state and/or unable to handle exceptions.
So, how is this usually handled?
I tried to direct the calls thru a linker-made gates, that would track the change of affinity, but that had cumulative effects of breaking other things, which had to be fixed, etc, etc...
Eventually everything worked out perfectly, but stepping back i see an intricate (but rugged) Rube Goldberg machine, which gets me here with a question - how is it handled properly/usually?