php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75327 PECL sync readerwriter lock problem
Submitted: 2017-10-06 12:43 UTC Modified: 2017-10-07 09:13 UTC
From: zhangsy at 1pei dot com dot cn Assigned:
Status: Closed Package: PECL (PECL)
PHP Version: 7.1.10 OS: centos 6.2
Private report: No CVE-ID: None
 [2017-10-06 12:43 UTC] zhangsy at 1pei dot com dot cn
Description:
------------
In the tests\014.phpt, the last fourth expect result should be bool(false), not bool(true), because the fourth writelock has not unlocked.

	var_dump($readwrite->readlock(0));
	var_dump($readwrite->readlock(0));
	var_dump($readwrite->readunlock());
	var_dump($readwrite->writelock(0));
	var_dump($readwrite->readunlock());
	var_dump($readwrite->readunlock());
	var_dump($readwrite->writelock(0));
	var_dump($readwrite->writelock(0));
	var_dump($readwrite->readlock(0));
	var_dump($readwrite->writeunlock());
?>
--EXPECT--
bool(true)
bool(true)
bool(true)
bool(false)
bool(true)
bool(false)
bool(true) <----Here should be false
bool(false)
bool(false)
bool(true)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-06 12:49 UTC] zhangsy at 1pei dot com dot cn
-Summary: sync readerwriter lock problem +Summary: PECL sync readerwriter lock problem -Package: *General Issues +Package: PECL
 [2017-10-06 12:49 UTC] zhangsy at 1pei dot com dot cn
update package to PECL sync
 [2017-10-06 12:56 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2017-10-06 12:56 UTC] requinix@php.net
No? The first writelock was denied because there was still a readlock in place.

var_dump($readwrite->readlock(0));   // shared lock #1 - true
var_dump($readwrite->readlock(0));   // shared lock #2 - true
var_dump($readwrite->readunlock());  // unlocked #2 - true
var_dump($readwrite->writelock(0));  // still locked by #1 - false <<<
var_dump($readwrite->readunlock());  // unlock #1 - true
var_dump($readwrite->readunlock());  // not locked - false
var_dump($readwrite->writelock(0));  // exclusive lock #1 - true
var_dump($readwrite->writelock(0));  // locked by #1 - false
var_dump($readwrite->readlock(0));   // locked by #1 - false
var_dump($readwrite->writeunlock()); // unlock #1 - true
 [2017-10-07 04:26 UTC] cubic@php.net
As the author of the extension, I agree.  The first write lock call fails because there is still a read lock.  The second write lock call succeeds since there are no read locks.  The third write lock call fails since there is already a write lock.

The test suite is carefully calibrated to cover the widest range of locking/unlocking scenarios with as little code as possible within a single process space (i.e. if something is locked, then it will not wait and will immediately return false).  Are you encountering a test suite validation error when running the tests?
 [2017-10-07 09:13 UTC] zhangsy at 1pei dot com dot cn
-Status: Feedback +Status: Closed
 [2017-10-07 09:13 UTC] zhangsy at 1pei dot com dot cn
The first writelock was denied, you are right.
This is not a bug.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Jul 04 18:01:26 2020 UTC