GithubHelp home page GithubHelp logo

pthreads-pool's Introduction

Pthreads Pool

An implementation of a thread pool for pthreads

Example

namespace Camspiers\Pthreads;

require_once 'vendor/autoload.php';

class Job extends Work
{
    protected function process()
    {
        // Do some work, and optionally return some data
        return range(1, 1000);
    }
}

$pool = new Pool();

for ($i = 0; $i < 1000; $i++) {
    $pool->submitWork(new Job());
}

// get jobs as they finish
foreach ($pool->getFinishedJobs() as $job) {
    var_dump($job->getData());
}

$pool->shutdown();

Working with an autoloader

In pthreads you need to register a autoload in each thread (or worker). The can be achieved by setting a loader on the pool.

$loader = require 'vendor/autoload.php';

$pool = new \Camspiers\Pthreads\Pool();
$pool->setLoader($loader);

// Use the pool

pthreads-pool's People

Contributors

camspiers avatar

Stargazers

Dmitrii D avatar joaner avatar KK avatar LC avatar Stevie Mayhew avatar  avatar Ignacio Muñoz Fernández avatar Simon Bennett avatar

Watchers

 avatar James Cloos avatar LC avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.