diff --git a/src/coreclr/src/gc/gc.cpp b/src/coreclr/src/gc/gc.cpp index 13a8335141bc4..abbabb66af40f 100644 --- a/src/coreclr/src/gc/gc.cpp +++ b/src/coreclr/src/gc/gc.cpp @@ -1022,50 +1022,44 @@ class t_join if (Interlocked::CompareExchange(&join_struct.r_join_lock, 0, join_struct.n_threads) == 0) { - if (!join_struct.wait_done) - { - dprintf (JOIN_LOG, ("r_join() Waiting...")); + fire_event (gch->heap_number, time_start, type_join, join_id); - fire_event (gch->heap_number, time_start, type_join, join_id); + dprintf (JOIN_LOG, ("r_join() Waiting...")); - //busy wait around the color - if (!join_struct.wait_done) - { + //busy wait around the color respin: - int spin_count = 256 * yp_spin_count_unit; - for (int j = 0; j < spin_count; j++) - { - if (join_struct.wait_done) - { - break; - } - YieldProcessor(); // indicate to the processor that we are spinning - } - - // we've spun, and if color still hasn't changed, fall into hard wait - if (!join_struct.wait_done) - { - dprintf (JOIN_LOG, ("Join() hard wait on reset event %d", first_thread_arrived)); - uint32_t dwJoinWait = join_struct.joined_event[first_thread_arrived].Wait(INFINITE, FALSE); - if (dwJoinWait != WAIT_OBJECT_0) - { - STRESS_LOG1 (LF_GC, LL_FATALERROR, "joined event wait failed with code: %Ix", dwJoinWait); - FATAL_GC_ERROR (); - } - } - - // avoid race due to the thread about to reset the event (occasionally) being preempted before ResetEvent() - if (!join_struct.wait_done) - { - goto respin; - } + int spin_count = 256 * yp_spin_count_unit; + for (int j = 0; j < spin_count; j++) + { + if (join_struct.wait_done) + { + break; + } + YieldProcessor(); // indicate to the processor that we are spinning + } - dprintf (JOIN_LOG, ("r_join() done")); + // we've spun, and if color still hasn't changed, fall into hard wait + if (!join_struct.wait_done) + { + dprintf (JOIN_LOG, ("Join() hard wait on reset event %d", first_thread_arrived)); + uint32_t dwJoinWait = join_struct.joined_event[first_thread_arrived].Wait(INFINITE, FALSE); + if (dwJoinWait != WAIT_OBJECT_0) + { + STRESS_LOG1 (LF_GC, LL_FATALERROR, "joined event wait failed with code: %Ix", dwJoinWait); + FATAL_GC_ERROR (); } + } - fire_event (gch->heap_number, time_end, type_join, join_id); + // avoid race due to the thread about to reset the event (occasionally) being preempted before ResetEvent() + if (!join_struct.wait_done) + { + goto respin; } + dprintf (JOIN_LOG, ("r_join() done")); + + fire_event (gch->heap_number, time_end, type_join, join_id); + return FALSE; } else