title: Is it possible to make a piece of code atomic (C#)?
body: <p>When I said atomic, I meant set of instructions will execute without any context switching <strong>to another thread on the same process</strong> (other kinds of switches have to be done of course). The only solution I came up with is to suspend all threads except currently executed before part and resume them after it. Any more elegant way?</p>
  
  <p>The reason I want to do that is to collect a coherent state of objects running on multiple threads. However, their code cannot be changed (they're already compiled), so I cannot insert mutexes, semaphores, etc in it. The atomic operation is of course state collecting (i.e. copying some variables).</p>