adilab/critical-section

PHP 的临界区功能

v1.0.0 2016-04-16 21:13 UTC

This package is not auto-updated.

Last update: 2024-09-20 19:09:32 UTC


README

允许创建一个代码临界区,其中只有确定数量的进程可以进入。

安装

首选的安装方式是使用 Composer

使用 composer 安装此库

$ composer require adilab/critical-section

使用

使用方法以检查进程是否可以进入临界区。

require('vendor/autoload.php');

use Adi\System\CriticalSection;

$cs = new CriticalSection();
if (!$cs->hasAccess()) 
	die("There are other process in executing...\n");
echo "Processing...\n";
$cs = NULL; // Destructs (closes) the critical section.

进程可以等待其他进程进入性能关键区。

require('vendor/autoload.php');

use Adi\System\CriticalSection;

$cs = new CriticalSection();
$cs->waitAccess();
echo "Processing...\n";

文档

API 文档