Real Spin Lock Solution

last modified: August 12, 2013

Compare this with SpinLock.

This is not very optimal, I think this a very simple solution that has no RaceCondition or DeadLock problem:

if ( lock.isLocked() )

{
  CLI // Avoid ContextChange
  for ( int i = 0; i < 200 && lock.isLocked(); i++ )
    ;
  STI
},
lock.waitForLock(); // Either lock immediately or do a ContextChange until lock is taken
doTask();
lock.dropLock();

This won't work on a multi-cpu where context change does not take place through IRQs.


Loading...