ThreadPool

Thread Pool Manages bounch of threads to execute given jobs as quickly as possible There are no priorities beetween jobs. Jobs added to queues in same order as they are in slices, but due to job stealing and uneven speed of execution beetween threads jobs execution order is unspecified. Number of threads executing jobs can be dynamically changed in any time. Threads removed from execution will work until the end of the program but shouldn't accept new jobs.

Destructor

~this
~this()

Clean ups ThreadPool

Members

Aliases

FlushLogsDelegaste
alias FlushLogsDelegaste = void delegate(ThreadData* threadData, JobLog[] logs)
Undocumented in source.

Functions

addGroup
void addGroup(JobsGroup* group, JobsGroup* spawnedByGroup)

Adds group of jobs to threadPool Spwaning group will finish after this group have finished

addGroupAsynchronous
void addGroupAsynchronous(JobsGroup* group)

Adds group of jobs to threadPool, group won't be synchronized

addJob
void addJob(JobData* data, int threadNum)

Adds job to be executed by thread pool, group specified in group data won't be finished until this job ends If threadNum is different than -1 only thread with threadNum will be able to execute given job

addJobAsynchronous
void addJobAsynchronous(JobData* data, int threadNum)

Adds job to be executed by thread pool, such a job won't be synchronized with any group or job If threadNum is different than -1 only thread with threadNum will be able to execute given job It is advised to use synchronized group of jobs

addJobsRange
void addJobsRange(Range rng, int threadNum)

Adds multiple jobs at once Range has to return JobData* Range has to have length property Range is used so there is no need to allocate JobData*[] All jobs has to belong to one group If threadNum is different than -1 only thread with threadNum will be able to execute given jobs

defaultFlushLogs
void defaultFlushLogs(ThreadData* threadData, JobLog[] logs)

Default implementation of flushing logs Saves logs to trace.json file in format acceptable by Google Chrome tracking tool chrome://tracing/ Logs can be watched even if apllication crashed, but might require removing last log entry from trace.json

flushAllLogs
void flushAllLogs()

Explicitly calls onFlushLogs on all threads

initialize
void initialize()

Initialize thread pool

jobsDoneCount
int jobsDoneCount()
Undocumented in source. Be warned that the author may not have intended to support it.
jobsDoneCountReset
void jobsDoneCountReset()
Undocumented in source. Be warned that the author may not have intended to support it.
registerExternalThread
ThreadData* registerExternalThread()

Registers external thread to thread pool array. There will be allocated data for this thread and it will have specified id External threads are not joined at the end of thread pool execution Returns ThreadData corresponding to external thread. To acually start executing, external thread had to call threadStartFunc() from returned variable

releaseExternalThreads
void releaseExternalThreads()

Allows external threads to return from threadStartFunc

setThreadsNum
void setThreadsNum(int num)

Sets number of threads to accept new jobs If there were never so much threads created, they will be created If number of threads set is smaller than there was threads before, they are not joined but they stop getting new jobs, they stop stealing jobs and they sleep longer Locking operation

unregistExternalThread
void unregistExternalThread(ThreadData* threadData)

Unregisters external thread. Can be called only when external thread have left the thread pool

waitThreads
void waitThreads()

Waits for all threads to finish and joins them (excluding external threads)

Static functions

getCPUCoresCount
int getCPUCoresCount()
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

logsCacheNum
int logsCacheNum;

Number of log cache entries. Should be set before setThreadsNum is called

onFlushLogs
FlushLogsDelegaste onFlushLogs;

User custom delegate to flush logs, if overriden defaultFlushLogs will be used. Can be sset after initialize() call

tryWaitCount
int tryWaitCount;

Number of times which tryWait are called before timedWait call. Higher value sets better response but takes CPU time even if there are no jobs.

Meta