[runtime] Fix an infinite loop in the runtime class init code. (#4455)
authorZoltan Varga <vargaz@gmail.com>
Thu, 2 Mar 2017 21:08:00 +0000 (16:08 -0500)
committerGitHub <noreply@github.com>
Thu, 2 Mar 2017 21:08:00 +0000 (16:08 -0500)
commitc667ba8f62212e16b64e2914a181fac7de26906f
treee1583896123d2ad0c94c5cdf89d4a742ef307496
parenta5624bf9ea51ec48fcfc6eede409dc9ceda3d5d4
[runtime] Fix an infinite loop in the runtime class init code. (#4455)

The following can happen:
* Thread T1 starts initialization of C1
* Thread T2 starts initialization of C2
* T2 starts initialization of C1, it gets blocked on T1.
* T1 finishes initializing C1.
* T1 starts initialization of C3.
* T1 starts initialization of C2. It sees that T2 is
  still blocked on T1, but its not actually blocked, since
  C1 is finished. Still, we record that T1 is blocked.
* T3 starts initialization of C2, it gets into an infinite
  loop in the while loop, since the blocked_thread_hash
  now indicates that T1 and T2 are blocked on each other.

The solution is to not mark a thread as blocked, if its waiting
for a thread which is waiting on a finished lock. Fixes hangs
when running csc.
mono/metadata/object.c