title: Can a .NET thread be interrupted between a method returning and assigning its return value (without terminating the process)?
body: <p>Is it possible for a .NET thread to somehow stop executing in-between the time a method returns and the time its return value is assigned to a variable/field? Of course, it's possible for the entire process to be terminated or the machine switched off, but is this possible with the process continuing to run?</p>
  
  <p>For example:</p>
  
  <pre><code>class Test
  {
       public static readonly Mutex MyMutex = new Mutex(false);
       public static bool MutexAcquired = false;
  
       private static bool AcquireMutex() =&gt; MyMutex.WaitOne(1000);
  
       public static void DoSomething()
       {
           MutexAcquired = AcquireMutex();
       }
  }
  </code></pre>
  
  <p>Is it possible that running <code>DoSomething()</code> will acquire the mutex (<code>WaitOne</code> returns true) but something will interrupt the thread before the value <code>MutexAcquired</code> is changed from <code>false</code> to <code>true</code> (but the process somehow continues running, so something can still read the wrong value of <code>MutexAcquired</code>)? Would it be any different if <code>MutexAcquired</code> was a local instead of a field?</p>
  
  <p>(I realise that, as written, the <code>AcquireMutex</code> method will probably be inlined, but let's assume it's more complex in practice, so it's not inlined.) </p>