Engine\Engine\Source\Runtime\Core\Public\HAL\ThreadingBase.h
/**
* Interface for "runnable" objects.
*
* A runnable object is an object that is "run" on an arbitrary thread. The call usage pattern is
* Init(), Run(), Exit(). The thread that is going to "run" this object always uses those calling
* semantics. It does this on the thread that is created so that any thread specific uses (TLS, etc.)
* are available in the contexts of those calls. A "runnable" does all initialization in Init().
*
* If initialization fails, the thread stops execution and returns an error code. If it succeeds,
* Run() is called where the real threaded work is done. Upon completion, Exit() is called to allow
* correct clean up.
*/
class CORE_API FRunnable
实现一个这个类的子类。
Thread = FRunnableThread::Create(param1, ThreadDescription, 128 * 1024, TPri_AboveNormal, FPlatformAffinity::GetPoolThreadMask());
第一个参数就是自己的创建的类的子类的指针。创建线程。
如果只有一个简单的任务,不用新开线程,直接创建分发一个task就行,会有一个线程去执行。
TGraphTask<FTaskClass>::CreateTask().ConstructAndDispatchWhenReady(this, Parm1,Parm2);
参数为FTaskClass构造函数的参数。
FTaskClass必须实现一个DoTask函数。