A* Pathfinding Project  4.1.19
The A* Pathfinding Project for Unity 3D
ParallelWorkQueue< T > Class Template Reference

Helper for parallelizing tasks. More...

Detailed Description

Helper for parallelizing tasks.

More specifically this class is useful if the tasks need some large and slow to initialize 'scratch pad'. Using this class you can initialize a scratch pad per thread and then use the appropriate one in the task callback (which includes a thread index).

Any exception that is thrown in the worker threads will be propagated out to the caller of the Run method.

Public Member Functions

 ParallelWorkQueue (Queue< T > queue)
 
IEnumerable< int > Run (int progressTimeoutMillis)
 Execute the tasks. More...
 

Public Attributes

System.Action< T, int > action
 Callback to run for each item in the queue. More...
 
readonly int threadCount
 Number of threads to use. More...
 

Private Member Functions

void RunTask (int threadIndex)
 

Private Attributes

readonly int initialCount
 
System.Exception innerException
 
readonly Queue< T > queue
 Queue of items. More...
 
ManualResetEvent [] waitEvents
 

Constructor & Destructor Documentation

◆ ParallelWorkQueue()

ParallelWorkQueue ( Queue< T >  queue)

Member Function Documentation

◆ Run()

IEnumerable<int> Run ( int  progressTimeoutMillis)

Execute the tasks.

Parameters
progressTimeoutMillisThis iterator will yield approximately every progressTimeoutMillis milliseconds. This can be used to e.g show a progress bar.

◆ RunTask()

void RunTask ( int  threadIndex)
private

Member Data Documentation

◆ action

System.Action<T, int> action

Callback to run for each item in the queue.

The callback takes the item as the first parameter and the thread index as the second parameter.

◆ initialCount

readonly int initialCount
private

◆ innerException

System.Exception innerException
private

◆ queue

readonly Queue<T> queue
private

Queue of items.

◆ threadCount

readonly int threadCount

Number of threads to use.

◆ waitEvents

ManualResetEvent [] waitEvents
private

The documentation for this class was generated from the following file: