Conversation
src/global.c
Outdated
There was a problem hiding this comment.
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.