|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-02-17 13:58 UTC] amancio at prjc dot com dot br
Description:
------------
Using package 'sync' PECL extension;
When an instance of SyncEvent calls fire() in a thread, the other instance of SyncEvent just gets fired if it is executing wait(). If the thread is processing other things, the next call to wait() will wait indefinitely.
This bad behaviour was observed just on Linux with sync 1.1.0. On Windows, sync 1.1.0 behaves correctly (the next call to wait() knows the event was already fired). Sync 1.0.1 (the previous version) behaves correctly on both platforms, Windows and Linux.
Test script:
---------------
// a single-threaded example:
$event = new SyncEvent("Test-123", true);
$event->fire();
if ($event->wait(0))
echo "Fired, ok";
else
echo "Not fired?";
Expected result:
----------------
On any platform, any version should have to print "Fired, ok".
Actual result:
--------------
On Windows, Sync 1.0.1 and 1.1.0 prints "Fired, ok".
On Linux, Sync 1.0.1 prints "Fired, ok", but Sync 1.1.0 prints "Not fired?".
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 06:00:01 2025 UTC |
Hi Thomas, thank you for spending your time on this! This time I did more extensive tests to get better details about the problem. I tested on 3 different Linux boxes: * An Arch Linux, kernel 4.8.13-1-ARCH, apache 2.4.25, PHP 5.6.30; * A CentOS 7.2.1511, kernel 3.10.0-327.36.3.el7.x86_64, apache 2.4.6, PHP 5.4.16; * A CentOS 6.6, kernel 2.6.32-504.8.1.el6.x86_64, apache 2.2.15, PHP 5.3.3; I slightly changed the test script to make two of it: // Test script A $event = new SyncEvent("Test-123", true); var_dump($event->wait(0)); // pay attention here var_dump($event->fire()); var_dump($event->wait(0)); var_dump($event->reset()); // Test script B $event = new SyncEvent("Test-123", true); var_dump($event->wait(1)); // you can put any number > 0 here var_dump($event->fire()); var_dump($event->wait(0)); var_dump($event->reset()); In any Linux box, the first (clean) run of any script creates a /dev/shm/Sync_Event-* file with 0666 permission. The first run of test script A always works: it prints bool(false) bool(true) bool(true) bool(true). And in all cases, test script B always fails: it prints bool(false) bool(true) bool(false) bool(true). In both CentOS boxes, new executions of script A always work, but script B never works. Even alternating the order of execution doesn't change this result. But in Arch Linux, a simple run of script B breaks something. Any subsequent run of script A prints bool(false) bool(true) bool(false) bool(true), until I manually remove the /dev/shm/Sync_Event-* file. I ran the tests as you suggested. In both CentOS, all 16 tests passed, but in Arch two tests failed: FAIL [14/16] SyncReaderWriter - named reader-writer allocation, locking, and unlocking freeze test.[/usr/share/php56/pear/test/sync/tests/014.phpt] FAIL [16/16] SyncSharedMemory - named shared memory allocation reuse test.[/usr/share/php56/pear/test/sync/tests/016.phpt] 2 FAILED TESTS: /usr/share/php56/pear/test/sync/tests/014.phpt /usr/share/php56/pear/test/sync/tests/016.phpt If you need more information, I am willing to help.