Non-GameTthread调用GameThread。
——————————————————
案例:
游戏起一个socket客户端与外部socket 服务器保持长连接通信;开辟一个接受线程(via. FRunnableThread::Create)来接受socket服务器的消息,然后在接受消息处理中有涉及到调用GameInstance或GameMode中的方法,导致程序宕掉(自个写的一个简单demo上又都正常,猜测可能是所调用方法的具体实现不同导致的)。
后面用IsInGameThread()判断,在处理函数中触发回调时间的时候,是出于非GameThread的,问题可能在于此?
然后google了下,比较有参考价值的如下两条:
1.How do I execute code on the Game thread from an FRunnable thread?
2.[UE4]如何跨线程访问GameThread中的数据
https://blog.csdn.net/wag2765/article/details/84796693
https://aigo.iteye.com/blog/2296553
大致的方法都是在主线程创建一个队列(eg.static TQueue<FString> To_be_synchronized_object; ),然后子线程收到socket消息时,往主线程的队列里塞,然后主线程在tick中去取队列消息,进行处理。
符些参考的链接,含队列:
https://wiki.unrealengine.com/Multi-Threading:_How_to_Create_Threads_in_UE4#What_Not_to_Do
https://zhuanlan.zhihu.com/p/38881269
https://answers.unrealengine.com/questions/702658/when-i-use-tqueuegot-a-compiler-error.html
https://www.reddit.com/r/unrealengine/comments/6ll3ty/tqueue_initialization/
====================================================================================
//AsyncTask (ENamedThreads::GameThread ,[](){
// //此处在游戏线程上执行的代码
//});
待研究。。。