1
0
mirror of https://github.com/danog/parallel.git synced 2024-11-26 20:34:40 +01:00

Fix semaphores sometimes not removed after termination

This commit is contained in:
coderstephen 2015-07-10 18:24:58 -05:00
parent e9f09077c9
commit b0e19519d0
2 changed files with 14 additions and 2 deletions

View File

@ -87,7 +87,8 @@ abstract class ForkContext extends Synchronized implements ContextInterface
// Get the fatal exception from the process.
return $this->parentSocket->read(2)->then(function ($data) {
list($serializedLength) = unpack('S', $data);
$serializedLength = unpack('S', $data);
$serializedLength = $serializedLength[1];
return $this->parentSocket->read($serializedLength);
})->then(function ($data) {
$previous = unserialize($data);
@ -162,4 +163,15 @@ abstract class ForkContext extends Synchronized implements ContextInterface
* {@inheritdoc}
*/
abstract public function run();
public function __destruct()
{
parent::__destruct();
// The parent process outlives the child process, so don't destroy the
// semaphore until the parent exits.
if (!$this->isChild) {
$this->semaphore->destroy();
}
}
}

View File

@ -15,7 +15,7 @@ abstract class Synchronized
{
private $memoryBlock;
private $memoryKey;
private $semaphore;
protected $semaphore;
/**
* Creates a new synchronized object.