File: Design.md

package info (click to toggle)
cthreadpool 0.0%2Bgit20170424-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 224 kB
  • sloc: ansic: 566; sh: 182; makefile: 16
file content (47 lines) | stat: -rw-r--r-- 2,169 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
## High level
	
	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.
	         
	             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.
	
	             In this header file a detailed overview of the functions and the threadpool's logical
	             scheme is presented in case you wish to tweak or alter something. 
	
	
	
	              _______________________________________________________        
	            /                                                       \
	            |   JOB QUEUE        | job1 | job2 | job3 | job4 | ..   |
	            |                                                       |
	            |   threadpool      | thread1 | thread2 | ..            |
	            \_______________________________________________________/
	
	
	   Description:       Jobs are added to the job queue. Once a thread in the pool
	                      is idle, it is assigned with the first job from the queue(and
	                      erased from the queue). It's each thread's job to read from 
	                      the queue serially(using lock) and executing each job
	                      until the queue is empty.
	
	
	   Scheme:
	
	   thpool______                jobqueue____                      ______ 
	   |           |               |           |       .----------->|_job0_| Newly added job
	   |           |               |  rear  ----------'             |_job1_|
	   | jobqueue----------------->|           |                    |_job2_|
	   |           |               |  front ----------.             |__..__| 
	   |___________|               |___________|       '----------->|_jobn_| Job for thread to take
	
	
	   job0________ 
	   |           |
	   | function---->
	   |           |
	   |   arg------->
	   |           |         job1________ 
	   |  next-------------->|           |
	   |___________|         |           |..