This file includes necessary Checks and includes the the nesessary libraries of the library.
The structure for a Thread Pool.
Definition thpool.h:47
pthread_cond_t thpool_works_cond
Used to synchronize the acces to thpool_works.
Definition thpool.h:72
pthread_mutex_t thpool_workers_MUTEX
Used to synchronize the acces to thpool_workers.
Definition thpool.h:61
_Atomic int stop
If set = 1 the thpool_handler will stop creating "workers" and wait till all already exising "workers...
Definition thpool.h:88
SNF_thpool_worker * thpool_workers
This LinkedList will store the currently working "workers" or more exactly the worker thread info.
Definition thpool.h:55
int max_workers_count
Limiter for the amount of threads that could be created.
Definition thpool.h:84
pthread_mutex_t thpool_noworks_MUTEX
Used to synchronize if all "works" are handled and all "workers" had finished their assigned "work" S...
Definition thpool.h:65
pthread_t * thpool_main_worker
The main function that is runs first when the Thread pool has started.
Definition thpool.h:76
pthread_mutex_t thpool_works_MUTEX
Used to synchronize the acces to thpool_works.
Definition thpool.h:58
_Atomic int thpool_n_works
Defines current amount of currently awaiting "works".
Definition thpool.h:51
sem_t thpool_workers_sem
Semaphore used for synchronization; Used primarly to notify the conclusion of "workers" to the Thread...
Definition thpool.h:81
pthread_t * thpool_handler
Thread that manages "workers" and assign their "work" to them.
Definition thpool.h:74
pthread_cond_t thpool_noworks_cond
Used to synchronize if all "works" are handled and all "workers" had finished their assigned "work" S...
Definition thpool.h:69
SNF_thpool_work * thpool_works
This LinkedList will store the "works" or "jobs".
Definition thpool.h:49
Defines the 'work' needed to do by defining a 'func'tion and it's 'arg'ument.
Definition thpool.h:25
SNF_thpool_work * next
Saves the next work ( Linked List )
Definition thpool.h:35
SNF_thpool_worker * worker
The thread pool's handling worker.
Definition thpool.h:33
void * arg
the argument to be given upon execution
Definition thpool.h:29
thpool * pool
the source Thread Pool
Definition thpool.h:31
Defines the 'worker'that would handle a certain 'work'.
Definition thpool.h:39
pthread_t * worker
The worker's thread id.
Definition thpool.h:41
SNF_thpool_worker * next
Pointer to workers' Linked list.
Definition thpool.h:43
void snf_thpool_stop(thpool *pool)
will stop creating "workers" and wait till all already exising "workers" finish their "work"
void snf_thpool_join(thpool *pool)
Will Block till the Main_worker finishes.
void snf_thpool_wait(thpool *pool)
Blocks current thread until there is No "Worker" is working and no "work" is waiting in queue.
int snf_thpool_inis(thpool **ThreadPool, int Max_Threads, void *(*Main_Worker)(), void *arg)
Insitanciates a new thread pool, with a Limiter ( Max_Threads )
void snf_thpool_addwork(thpool *pool, void *(*func)(), void *arg)
Creates a "work" that will call the func function with argument arg