21 lines
550 B
PHP
21 lines
550 B
PHP
|
<?php
|
||
|
|
||
|
require_once __DIR__."/../vendor/autoload.php";
|
||
|
|
||
|
use NoccyLabs\Ipc\Key\FileKey;
|
||
|
use NoccyLabs\Ipc\Sem\Semaphore;
|
||
|
|
||
|
$key = new FileKey(__FILE__);
|
||
|
|
||
|
// Create semaphore with max count of 2
|
||
|
$sem1 = new Semaphore($key, 2);
|
||
|
$sem2 = new Semaphore($key, 2);
|
||
|
$sem3 = new Semaphore($key, 2);
|
||
|
|
||
|
printf("sem1 acquire: %d\n", $sem1->acquire());
|
||
|
printf("sem2 acquire: %d\n", $sem2->acquire());
|
||
|
printf("sem3 acquire: %d\n", $sem3->acquire());
|
||
|
printf("sem2 release: %d\n", $sem2->release());
|
||
|
printf("sem3 acquire: %d\n", $sem3->acquire());
|
||
|
|
||
|
$sem1->destroy();
|