I haven't posted for a while, and this isn't really a deserving post, so I apologize for that.
This is however, something I can never seem to keep straight in my head, so I'm throwing it out here to keep track of it for myself and possibly others.
How Static Variables within Shared Libraries (C or C++) Work Under Linux
Static variables within shared libraries for the most part work exactly as they do directly in an executable, on a per process basis. There is no consistency of value between multiple processes using the same shared library.
Each process will have all static data within these shared libraries initialized to zero, and then their scope will be maintained throughout the lifetime of that process, independent of other processes.
I have tested this empirically and found it to be true, and in line with how I theorized that it worked. If you know otherwise and can explain it to me (and shatter my understanding of the world) - I would love to hear it.
6 years ago
3 comments:
Nope, you've got it right. I've never run into a shared library where this was not the case, (even under windows), so good luck trying to find the opposite true.
Thanks for good information Jason..
I'll also try it out...
Post a Comment