略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: pht\Queue::unlock

2024-04-30

pht\Queue::unlock

(PECL pht >= 0.0.1)

pht\Queue::unlockReleases the queue's mutex lock

说明

public pht\Queue::unlock ( void ) : void

This method will release the mutex lock associated with the queue.

参数

此函数没有参数。

返回值

No return value.

范例

Example #1 Locking a queue's mutex lock

<?php

use pht\{ThreadQueue};

$thread = new Thread();
$queue = new Queue();

$thread->addFunctionTask(function ($queue) {
    
$queue->lock();
    
$queue->push(1);
    
$queue->unlock();
}, 
$queue);

$thread->start();

// $queue is currently being used by multiple threads
$queue->lock();
$queue->push(1);
$queue->unlock();

$thread->join();

// $queue is only being used in this thread now, so no need to lock it
while ($queue->size()) {
    
var_dump($queue->pop());
}

以上例程会输出:

int(1)
int(1)
add a note add a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/pht-queue.unlock.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3