-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Multiple init #1890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple init #1890
Conversation
|
||
int git_threads_init(void) | ||
{ | ||
int error; | ||
|
||
if (_tls_init) | ||
if (git_atomic_inc(&git__n_inits) > 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this returns > 1, you still have to spin waiting on git__initialized
to be > 0 so that later threads will wait for the first thread to finish initialization.
Okay, this last couple of commits should guard against this race:
I kind of want to squash this all down when it's finalized. I hate to have points in our history where this specific API is so terribly broken. |
I am a little concerned with the fact that this is over-engineered because @arrbee's initial code for deinit was also over-engineered. Is the thread-safe and multi-shutdown API we have right now really necessary? I think one global init and one global shutdown should be the goal of all the people using the library. Can you think of use cases where this multiple initialization is a requirement? |
Libgit2Sharp has one, actually. A server process (like IIS) can spin up multiple AppDomains in a short period of time, and the static constructor for |
Squashed up, and Travis and Janky are happy. I think this is ready. |
Threads are C R A Y. Thanks for tacking this, guise! |
Multiple init
As discovered in libgit2/libgit2sharp#517, initializing the threadsafe mechanisms multiple times doesn't seem to have any ill effects, but bad things would start to happen after the first call to
git_threads_shutdown
.This PR converts the status variables to be something like a reference count, and the global threading primitives are only freed once the counter reaches zero.