Gorgon Game Engine
Gorgon::Threading Namespace Reference

Contains multi-threading functions and objects. More...

Functions

void RunAsync (std::function< void()> fn)
 Executes a function asynchronously. More...
 
void RunInParallel (std::function< void(int, int)> fn, unsigned threads=0)
 Runs a function specified amount of times in parallel. More...
 

Detailed Description

Contains multi-threading functions and objects.

For thread and mutex

See also
std::thread and std::mutex

Function Documentation

◆ RunAsync()

void Gorgon::Threading::RunAsync ( std::function< void()>  fn)

Executes a function asynchronously.

This function starts the thread immediately. There is no way to wait for the thread, stop or query its execution.

Parameters
fnthe function to be executed.

◆ RunInParallel()

void Gorgon::Threading::RunInParallel ( std::function< void(int, int)>  fn,
unsigned  threads = 0 
)

Runs a function specified amount of times in parallel.

threads parameter controls the amount of parallel executions. This function will return when all threads it controls finishes. The following example performs an operation over the data vector using 4 threads. If the threads parameter is omitted, the number of threads supported by hardware is used.

std::vector<int> data(1000);
RunInParallel([&data](int threadid, int threads) {
for(int i=threadid;i<data.size();i+=threads) {
//... do something with data[i]
}
}, 4);
Parameters
fnis the function to be executed. First parameter of the function should be thread id, second is the number of threads. See the example.
threadsthe number of threads to be executed.
Gorgon::Threading::RunInParallel
void RunInParallel(std::function< void(int, int)> fn, unsigned threads=0)
Runs a function specified amount of times in parallel.
Definition: Threading.h:40