This mutex doesn't lock at all. It implements the compare-and-swap approach. I.e. it will repeat executing the code block until it wasn't modified in between. Use this only when you know that concurrency is a rare event.
Автор: Markus Malkusch (markus@malkusch.de)
Наследование: extends Mutex
Пример #1
0
 /**
  * Tests that the code is executed more times.
  *
  * @test
  */
 public function testIteration()
 {
     $i = 0;
     $mutex = new CASMutex();
     $mutex->synchronized(function () use($mutex, &$i) {
         $i++;
         if ($i > 1) {
             $mutex->notify();
         }
     });
     $this->assertEquals(2, $i);
 }