+
+ /*
+ * An inquisitive mind could ask what's the deal with this loop.
+ * It exists to deal with interrupting a monitor enter that happened within an abort-protected block, like a .cctor.
+ *
+ * The thread will be set with a pending abort and the wait might even be interrupted. Either way, once we call mono_thread_interruption_checkpoint,
+ * it will return NULL meaning we can't be aborted right now. Once that happens we switch to non-alertable.
+ */
+ do {
+ res = mono_monitor_try_enter_internal (obj, MONO_INFINITE_WAIT, allow_interruption);
+ /*This means we got interrupted during the wait and didn't got the monitor.*/
+ if (res == -1) {
+ MonoException *exc = mono_thread_interruption_checkpoint ();
+ if (exc) {
+ mono_set_pending_exception (exc);
+ return FALSE;
+ } else {
+ //we detected a pending interruption but it turned out to be a false positive, we ignore it from now on (this feels like a hack, right?, threads.c should give us less confusing directions)
+ allow_interruption = FALSE;
+ }
+ }
+ } while (res == -1);
+ return TRUE;