To create a thread you will need to:
Locate your game's <your_game_asset_folder>/config/game.thread_config
<ThreadConfig>
<Platform name="PC_Common">
...
<Thread name ="FooThread" Affinity="5" Priority="Normal" StackSizeKB="32"/>
...
</Platform>
...
</ThreadConfig>
Note: If you skipped step 1, the default configuration of the given platform for your thread will be used.
#include <IThreadManager.h>
struct SMyThread : public IThread
{
SMyThread()
: m_bStop(false)
{
}
// Once the thread is up and running it will enter this method
virtual void ThreadEntry()
{
while (!m_bStop)
{
// Do work ... your code
}
// On return, thread dies
}
// Signal the thread to stop working
void SignalStopWork()
{
m_bStop = true;
}
volatile bool m_bStop; // Member variable to signal thread to break out of work loop
};
SFooThread* pFooThread = new SFooThread();
if (!gEnv->pThreadManager->SpawnThread(pFooThread , "FooThread"))
{
// your failure handle code
delete pFooThread;
CryFatalError(...);
}
m_pMyThread = pFooThread; // Store thread for later access