public testHighContention ( callable $code, callable $mutexFactory ) | ||
$code | callable | The counter code. |
$mutexFactory | callable | The mutex factory. |
public function testHighContention(callable $code, callable $mutexFactory)
{
$concurrency = max(2, ezcSystemInfo::getInstance()->cpuCount);
$iterations = 20000 / $concurrency;
$timeout = $concurrency * 20;
$this->fork($concurrency, function () use($mutexFactory, $timeout, $iterations, $code) {
$mutex = call_user_func($mutexFactory, $timeout);
for ($i = 0; $i < $iterations; $i++) {
$mutex->synchronized(function () use($code) {
call_user_func($code, 1);
});
}
});
$counter = call_user_func($code, 0);
$this->assertEquals($concurrency * $iterations, $counter);
}