Giter Club home page Giter Club logo

ctp's Introduction

ARCHIVED - Moved to gitlab

ARCHIVED - Moved to gitlab

CTP

The universal C-Thread-Pool library

CTP is a C library that offers a pool thread, based on pthread, that is the only dependency.
While easy to use, it has some interesting features:

Features

  • Cross platform: Standard C; Windows, linux, bsd; 32/64 bit
  • Can spawn the best number of threads according to detected cpu
  • Lazy thread activation
  • Ability to pause/resume
  • Automatic/custom queue size
  • Can block when adding work or discard if queue is full (best effort)
  • Possibility to know how many threads were effectively spawned
  • Dedicated API to query status in any moment (paused/idle/working)
  • Easy transition from pthread, the work prototype has the same signature

Installation

Just compile the .c file and add it to your linker, as object or library. If using gcc/clang, remember to complie with -pthread and link with -lpthread

If you want to use visual studio, or other windows compiler, use package https://sourceware.org/pthreads-win32

Configuration

While compiling ctp (The library, not the clients), you can pass these variables:

  • CTP_DEFAULT_THREADS_NUM
  • CTP_MULTIPLY_QUEUE_FACTOR
  • CTP_MIN_QUEUE_SIZE

CTP_DEFAULT_THREADS_NUM is used only if you pass 0 to init, and ctp fails to detect core number.
In this case, CTP_DEFAULT_THREADS_NUM threads will be used. Default is 4.
If you pass 0 to init in the second parameter, the queue size will be calculated according to 3 parameters:
threads-num, CTP_MULTIPLY_QUEUE_FACTOR and CTP_MIN_QUEUE_SIZE. The formula is:
max(threads-num * CTP_MULTIPLY_QUEUE_FACTOR, CTP_MIN_QUEUE_SIZE)
The default value for CTP_MULTIPLY_QUEUE_FACTOR is 8.
The default value for CTP_MIN_QUEUE_SIZE is 256


For API details see header file. Test file may help too

ctp's People

Contributors

mp81ss avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.