Skip to content

bennyhuo/tinycthreadpool

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple C thread pool implementation

UPDATE: I have replaced the original pthread with tinycthread, so it's working on both Windows and POSIX systems.

Currently, the implementation:

  • Works with pthreads only, but API is intentionally opaque to allow other implementations (Windows for instance).
  • [New] Based on tinycthread, provided Windows/Linux/macOS supports.
  • Starts all threads on creation of the thread pool.
  • Reserves one task for signaling the queue is full.
  • Stops and joins all worker threads on destroy.

How to Use

You can use the source code in your project directly.

But it becomes more easily to use conan.

  1. Install conan first according to this reference.

  2. add it to your conan.txt:

    [requires]
    ...
    tinycthreadpool/1.0
    
    
  3. At last, install or build the lib with conan automatically.

    conan install <path to conan.txt> --build=missing
    

Enjoy!

Possible enhancements

The API contains addtional unused 'flags' parameters that would allow some additional options:

  • Lazy creation of threads (easy)
  • Reduce number of threads automatically (hard)
  • Unlimited queue size (medium)
  • Kill worker threads on destroy (hard, dangerous)
  • Support Windows API (medium)
  • Reduce locking contention (medium/hard)

About

A simple C Thread pool implementation

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 97.4%
  • CMake 2.6%