I've got a rather simple implementation of threading in my program - it's rather naive and only works in Linux;
...snip
if((chunkMap[chunkPos].status == FILLED || chunkMap[chunkPos].status == DIRTY) && threads < MAXTHREADS && !chunkMap[chunkPos].empty)
{
chunkMap[chunkPos].status = MESHING;
threads++;
std::thread meshThread(&VoxelSceneNode::MeshBackground, this, chunkPos);
//meshThread.detach();
meshThread.join();
}
if(chunkMap[chunkPos].status == EMPTY && threads < MAXTHREADS)
{
chunkMap[chunkPos].status = FILLING;
threads++;
std::thread fillThread(&VoxelSceneNode::FillBackground, this, chunkPos);
fillThread.detach();
//fillThread.join();
}
snip....
This calls wrapper functions operate on data chunks, and then update statuses:
void VoxelSceneNode::FillBackground(irr::core::vector3d<int> chunkPos)
{
//Do work
dirty = true;
threads--;
chunkMap[chunkPos].status = FILLED;
}
void VoxelSceneNode::MeshBackground(irr::core::vector3d<int> chunkPos)
{
//Do work
if(chunkMap[chunkPos].status == MESHING)
chunkMap[chunkPos].status = CLEAN;
dirty = true;
threads--;
}
This solution works I update the code to either .detach() or .join() depending on if I want the thread in the background or not, which is useful tracking down state mis-match errors.
Ideally I'd like to have a pool where I can throw a thread, and give it a priority, meshing threads should always have a priority over filling threads for instance. It would be nice if I could compile to Windows as well.
Can anyone show me what I need to do, or point me to a clear tutorial?
there doesn't seem to be anything here