/**
* 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
虛幻4 創建線程
Engine\Engine\Source\Runtime\Core\Public\HAL\ThreadingBase.h
實現一個這個類的子類。
Thread = FRunnableThread::Create(param1, ThreadDescription, 128 * 1024, TPri_AboveNormal, FPlatformAffinity::GetPoolThreadMask());
第一個參數就是自己的創建的類的子類的指針。創建線程。
如果只有一個簡單的任務,不用新開線程,直接創建分發一個task就行,會有一個線程去執行。
TGraphTask<FTaskClass>::CreateTask().ConstructAndDispatchWhenReady(this, Parm1,Parm2);
參數爲FTaskClass構造函數的參數。
FTaskClass必須實現一個DoTask函數。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.