Fix for threadpool abort function
Fixed an issue where if threadpool was aborted when some threads were in a running state the threadpool would never exit. This was due to the fact that the thread terminate task (func == NULL && args == NULL) could have been pushed to queues which were inactive. This change adds a uint64_t mask of threads that have already exited so whenever the terminate task is sent to another queue, it is ensured that the queue used will wake up at least one tpool worker. Also added pushTpool_mask which allows to specify a subset of threads to push the task to but its only used internally. Also added in this commit: A way to allocate thread-safe storage for thread pool workers via get_tpool_worker_index. This index is unique to the thread pool worker within one threadpool and can be used to access arrays in a thread-safe manner. An example of such use was added in a testcase that was added which compares delay between actors and threadpool workers.
This commit is contained in:
@@ -50,6 +50,7 @@ typedef struct {
|
||||
void* q_arr;
|
||||
|
||||
pthread_barrier_t barrier;
|
||||
_Atomic(uint64_t) dead_mask;
|
||||
} tpool_t;
|
||||
|
||||
/// @brief Push job to threadpool. May run task inline in case there are no worker threads
|
||||
@@ -82,4 +83,8 @@ void initFloatingCoresTpool(int nbThreads,tpool_t *pool, bool performanceMeas, c
|
||||
|
||||
/// Convenience macro
|
||||
#define initTpool(PARAMPTR,TPOOLPTR, MEASURFLAG) initNamedTpool(PARAMPTR,TPOOLPTR, MEASURFLAG, NULL)
|
||||
|
||||
/// Returns the index of the worker thread in the thread pool
|
||||
/// @return index of the worker thread in a thread pool or -1 if not called from a thread pool worker thread
|
||||
int get_tpool_worker_index(void);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user