A simple thread pool implementation that uses POSIX pthread
Go to file
Samer Afach 8853b01891 Updated header guard name 2017-03-27 08:53:26 +02:00
examples Added end of program to print 2017-01-15 13:34:03 +00:00
include Updated header guard name 2017-03-27 08:53:26 +02:00
src First commit 2017-01-15 11:16:00 +01:00
Makefile First commit 2017-01-15 11:16:00 +01:00
README.md Added readme file for git 2017-01-15 14:02:23 +00:00
Threadpool_pthread.pro First commit 2017-01-15 11:16:00 +01:00

README.md

Simple Thread Pool for POSIX pthread

This is a very simple implementation of a ThreadPool that uses POSIX threads. It's written to be simple, not versatile.

License

MIT. In other words, you're free to do with this code whatever you want.

Usage

There is an example on how to use the code in the directory examples.

Other than that, all you have to do is:

  • Include the file ThreadPool_pthread.h
  • Add the sources in the directory src to your sources
  • Link to pthread (with -pthread on Linux/MAC/POSIX systems, or download the Windows version of pthread and use it)
  • Start coding!

Using the code is very simple. All you have to do is:

  • Create an object ThreadPool_pthread pool(num), where num is the number of threads
  • Use the member function pool.push_task(function, parameters), to add tasks to the pool, where function is a function pointer to the function to be added, and parameters is a void* that contains the parameters.
  • Call pool.finish(), which will block until all tasks are finished.

Note: Return values in the function are omitted. Note: The function signature is void* function(void* parameters).

Makefiles

There's a make file that builds the example. There's also a qmake file that builds the example too.