首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

SyncMutex::__construct

(PECL sync >= 1.0.0)

SyncMutex::__construct — Constructs a new SyncMutex object

Description

代码语言:javascript
复制
public SyncMutex::__construct ([ string $name ] )

Constructs a named or unnamed countable mutex.

Parameters

name

The name of the mutex if this is a named mutex object.

Note: If the name already exists, it must be able to be opened by the current user that the process is running as or an exception will be thrown with a meaningless error message.

Return Values

The new SyncMutex object. An exception is thrown if the mutex cannot be created or opened.

Examples

Example #1 SyncMutex::__construct() named mutex with lock timeout example

代码语言:javascript
复制
<?php
$mutex?=?new?SyncMutex("UniqueName");

if?(!$mutex->lock(3000))
{
????echo?"Unable?to?lock?mutex.";

????exit();
}

/*?...?*/

$mutex->unlock();
?>

Example #2 SyncMutex::__construct() unnamed mutex example

代码语言:javascript
复制
<?php
$mutex?=?new?SyncMutex();

$mutex->lock();

/*?...?*/

$mutex->unlock();
?>

See Also

  • SyncMutex::lock() - Waits for an exclusive lock
  • SyncMutex::unlock() - Unlocks the mutex

← SyncMutex

SyncMutex::lock →

代码语言:txt
复制
 ? 1997–2017 The PHP Documentation Group

Licensed under the Creative Commons Attribution License v3.0 or later.

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com