Coder Social home page Coder Social logo

jonhoo / pthread_pool Goto Github PK

View Code? Open in Web Editor NEW
76.0 6.0 26.0 180 KB

A simple implementation of thread pooling for C/C++ using POSIX threads

License: MIT License

C 99.64% C++ 0.36%
pthreads multi-core multithreading thread-pool posix-threads

pthread_pool's Introduction

pthread_pool

A simple implementation of thread pooling for C/C++ using POSIX threads.

Each pool has a designated worker function, and expects to be given a number of work items. Any thread in the pool can take a work item, and will pass the work item to the pool's worker function. The work items are void *, and are passed to the worker function exactly as they are given to pool_enqueue. The return values of the worker functions are ignored.

Four functions of interest are provided:

  • pool_start will start a new pool. The worker function and number of threads in the pool need to be given as arguments.
  • pool_enqueue will add a new work item to the pool. The work item data pointer should be passed, as well as a flag specifying whether the work item should be free'd after the work item has been processed (or if the pool is terminated).
  • pool_wait will block until all queued work items have been processed.
  • pool_end should be called when the pool is no longer needed. This terminates the threads, deallocates the queue and the pool, as well as any freeable work items.

Further documentation is given in Doxygen format in pthread_pool.h.

pthread_pool's People

Contributors

jonhoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  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.