Fix race condition between a domain unload and a runtime shutdown.
commit41a6f4267b71431a6d6dba2bb1efbe80e30961fd
authorRodrigo Kumpera <kumpera@gmail.com>
Thu, 6 Jun 2013 22:53:39 +0000 (6 18:53 -0400)
committerRodrigo Kumpera <kumpera@gmail.com>
Thu, 6 Jun 2013 23:00:06 +0000 (6 19:00 -0400)
treec27813cfdf154495eaa78e9dc1c1f5e5f05e5ff3
parent523648de784942ae57f1ff0fb55f00916c768142
Fix race condition between a domain unload and a runtime shutdown.

When a regular runtime shutdown and a domain unload starts mostly in parallel
it might happen that the unload initiator will deadlock waiting on the unload thread
for two reasons:

The unload thread will block when attaching as the runtime believe it's better
to not finish it as it's going down. To fix this we now use mono_thread_attach_full
and force it to be attached.

The unload initiator might deadlock on the wait loop if the shutdown initiator aborts
it instead of the unload thread. This happens if the unload was done from outside of
the domain been teared down.

The fix here is to add a variable that the initiation test on every loop, which is the
right thing to do when using wait loops on handles. This might degrade into a busy
loop when the above race condition happens. It's rare enough that it's not worth
fixing it now.
mono/metadata/appdomain.c