v1.4 Register external threads to use with enkiTS
You can now configure enkiTS with numExternalTaskThreads which can be registered to use with the enkiTS API using the RegisterExternalThread function.
Developed based on request Feature suggestion: running tasks from non main/task threads #39 by @Vuhdo.
- This also introduces a new way to configure the task scheduler using the enki::TaskSchedulerConfig.
- C++11 branch is now deprecated (C++11 functionality now in master branch) and will no longer be updated as master is identical. Please switch to master if you are on this legacy branch.
- GetProfilerCallbacks no deprecated as you should use the enki::TaskSchedulerConfig.
External thread usage in C++:
- full example in example/ExternalTaskThread.cpp
- C example in example/ExternalTaskThread_c.c
#include "TaskScheduler.h"
enki::TaskScheduler g_TS;
struct ParallelTaskSet : ITaskSet
{
virtual void ExecuteRange( TaskSetPartition range, uint32_t threadnum )
{
// Do something
}
};
void threadFunction()
{
g_TS.RegisterExternalTaskThread();
// sleep for a while instead of doing something such as file IO
std::this_thread::sleep_for( std::chrono::milliseconds( num_ * 100 ) );
ParallelTaskSet task;
g_TS.AddTaskSetToPipe( &task );
g_TS.WaitforTask( &task);
g_TS.DeRegisterExternalTaskThread();
}
int main(int argc, const char * argv[])
{
enki::TaskSchedulerConfig config;
config.numExternalTaskThreads = 1; // we have one extra external thread
g_TS.Initialize( config );
std::thread exampleThread( threadFunction );
exampleThread.join();
return 0;
}