Shadow Network Framework
0.0.2-alpha
C Server Library for Shadow Network Framework
|
this file Defines everything related to ThreadPool More...
Go to the source code of this file.
Data Structures | |
struct | SNF_ThreadPool_work_t |
Defines the 'work' needed to do by defining a 'func'tion and it's 'arg'ument. More... | |
struct | SNF_ThreadPool_worker_t |
Defines the 'worker'that would handle a certain 'work'. More... | |
struct | SNF_ThreadPool_t |
The structure for a Thread Pool. More... | |
Typedefs | |
typedef struct SNF_ThreadPool_work_t | SNF_thpool_work |
typedef struct SNF_ThreadPool_worker_t | SNF_thpool_worker |
typedef struct SNF_ThreadPool_t | SNF_thpool |
typedef enum SNF_ThreadPool_Status_e | SNF_thpool_status |
Enumerations | |
enum | SNF_ThreadPool_Status_e { SNF_THPOOL_STOP , SNF_THPOOL_RUN , SNF_THPOOL_DESTROY } |
Functions | |
int | snf_thpool_inis (SNF_thpool **ThreadPool, int Max_Threads, void *(*Main_Worker)(void *), void *arg) |
Insitanciates a new thread pool, with a Limiter ( Max_Threads ) | |
void | snf_thpool_addwork (SNF_thpool *pool, void *(*func)(), void *arg) |
Creates a "work" that will call the func function with argument arg | |
void | snf_thpool_wait (SNF_thpool *pool) |
Blocks current thread until the Thread Pool's last changed status has taken effect. | |
void | snf_thpool_join (SNF_thpool *pool) |
Will Block till the Main_worker finishes. | |
void | snf_thpool_stop (SNF_thpool *pool) |
will order the Thread Pool to stop. | |
void | snf_thpool_run (SNF_thpool *pool) |
Variables | |
time_t | SNF_THPOOL_STOPWAIT |
This defines the amount of seconds to wait a worker to stop, if the worker does not stop during this time period it will be forcefully be stopped. | |
this file Defines everything related to ThreadPool
Thread Pools By Abdelhadi Seddar This implemantation of a Threadpool is by no means perfect nor optimized, because I made it based of a graph depicting how a threadpool works, without seeing any documentation about it, this is just a learning experience for me and im learning through trial and error.
UPDATE 0.0.2-alpha: After research and trial and error, and feedback from other people and after trying it in a project, i realized that i made the implementation wrong, as i used to create each threads whenever there is a work
to do, which added CPU Time and latency, so after Reading this Wikipedia Page (Last visited on Augest 2, 2024 at 2:37 PM GMT +1) I noticed that i should've created the threads At once and from the beggining. so i did just that in this update and it did do wonders after comparing the performance of the two (and doesnt crash as often as 0.0.1-alpha)
typedef struct SNF_ThreadPool_work_t SNF_thpool_work |
typedef struct SNF_ThreadPool_worker_t SNF_thpool_worker |
typedef struct SNF_ThreadPool_t SNF_thpool |
typedef enum SNF_ThreadPool_Status_e SNF_thpool_status |
|
extern |
Insitanciates a new thread pool, with a Limiter ( Max_Threads )
ThreadPool | Returns the thread pool by writes the newly created instance in the pointer given in this parameter |
Max_Threads | Maximum Total allowed threads ( Must be 2+ if No Main Worker given, else must me 3+ for proper work) |
Main_Worker | Main Function that would be called upon finishing the intialisation of the |
arg | the argument that would be given to the Main_worker function. |
|
extern |
Creates a "work" that will call the func function with argument arg
pool | The Thead Pool to be operated on. |
func | The function that would be called once a "worker" picks up the "work". |
arg | argument to be given to the func upon call. |
|
extern |
Blocks current thread until the Thread Pool's last changed status has taken effect.
pool | The Thead Pool to be operated on. |
|
extern |
Will Block till the Main_worker finishes.
pool | The Thead Pool to be operated on. |
|
extern |
will order the Thread Pool to stop.
pool | The Thead Pool to be operated on. |
|
extern |
|
extern |
This defines the amount of seconds to wait a worker
to stop, if the worker
does not stop during this time period it will be forcefully be stopped.