Skip to content
This repository was archived by the owner on Dec 16, 2019. It is now read-only.
This repository was archived by the owner on Dec 16, 2019. It is now read-only.

memory leak when pthreads in pthreads  #954

@Still4

Description

@Still4
<?php

$worker_num_total = 40;
$global_data = array();
$variables_list = array_pad(array(), 1000000, 0);
$variables = array_chunk($variables_list, 40);
foreach ($variables as $key => $chunks) {
    $pool = new \Pool($worker_num_total, \Worker::class);
    $pool->submit(new SecondThread($chunks));
    while (($worker_num = $pool->collect()) > 0) {
        usleep(100000);
    }
    $pool->shutdown();
    unset($pool);
    gc_collect_cycles();
}

class SecondThread extends \Thread
{

    private $chunks;

    public function __construct($chunks)
    {
        $this->chunks = $chunks;
    }

    public function run()
    {
        $pool = new \Pool(10, \Worker::class);
        foreach ($this->chunks as $chunk) {
            $pool->submit(new ThirdThread($chunk));
        }
        while (($worker_num = $pool->collect()) > 0) {
            usleep(100000);
        }
        $pool->shutdown();
        unset($pool);
        gc_collect_cycles();
    }

}

class ThirdThread extends \Thread
{

    private $chunk;

    public function __construct($chunk)
    {
        $this->chunk = $chunk;
    }

    public function run()
    {
        $this->chunk;
    }

}

?>

the first minute
image
about 5 mins later
image
about 10 mins later
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions