2015-01-15 11:41:17 +03:00
|
|
|
## High level
|
2020-07-20 19:00:26 +03:00
|
|
|
|
2015-01-15 11:41:17 +03:00
|
|
|
Description: Library providing a threading pool where you can add work on the fly. The number
|
|
|
|
of threads in the pool is adjustable when creating the pool. In most cases
|
|
|
|
this should equal the number of threads supported by your cpu.
|
2020-07-20 19:00:26 +03:00
|
|
|
|
2015-01-15 11:41:17 +03:00
|
|
|
For an example on how to use the threadpool, check the main.c file or just read
|
|
|
|
the documentation found in the README.md file.
|
2020-07-20 19:00:26 +03:00
|
|
|
|
2015-01-15 11:41:17 +03:00
|
|
|
In this header file a detailed overview of the functions and the threadpool's logical
|
2020-07-20 19:00:26 +03:00
|
|
|
scheme is presented in case you wish to tweak or alter something.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_______________________________________________________
|
2015-01-15 11:41:17 +03:00
|
|
|
/ \
|
2020-07-20 19:00:26 +03:00
|
|
|
| JOB QUEUE | job1 | job2 | job3 | job4 | .. |
|
2015-01-15 11:41:17 +03:00
|
|
|
| |
|
|
|
|
| threadpool | thread1 | thread2 | .. |
|
|
|
|
\_______________________________________________________/
|
2020-07-20 19:00:26 +03:00
|
|
|
|
|
|
|
|
2015-01-15 11:41:17 +03:00
|
|
|
Description: Jobs are added to the job queue. Once a thread in the pool
|
2020-07-20 19:00:26 +03:00
|
|
|
is idle, it is assigned the first job from the queue (and that job is
|
|
|
|
erased from the queue). It is each thread's job to read from
|
|
|
|
the queue serially (using lock) and executing each job
|
2015-01-15 11:41:17 +03:00
|
|
|
until the queue is empty.
|
2020-07-20 19:00:26 +03:00
|
|
|
|
|
|
|
|
2015-01-15 11:41:17 +03:00
|
|
|
Scheme:
|
2020-07-20 19:00:26 +03:00
|
|
|
|
|
|
|
thpool______ jobqueue____ ______
|
2015-01-15 11:41:17 +03:00
|
|
|
| | | | .----------->|_job0_| Newly added job
|
|
|
|
| | | rear ----------' |_job1_|
|
|
|
|
| jobqueue----------------->| | |_job2_|
|
2020-07-20 19:00:26 +03:00
|
|
|
| | | front ----------. |__..__|
|
2015-01-15 11:41:17 +03:00
|
|
|
|___________| |___________| '----------->|_jobn_| Job for thread to take
|
2020-07-20 19:00:26 +03:00
|
|
|
|
|
|
|
|
|
|
|
job0________
|
2015-01-15 11:41:17 +03:00
|
|
|
| |
|
|
|
|
| function---->
|
|
|
|
| |
|
|
|
|
| arg------->
|
2020-07-20 19:00:26 +03:00
|
|
|
| | job1________
|
2015-01-15 11:41:17 +03:00
|
|
|
| next-------------->| |
|
|
|
|
|___________| | |..
|