# How do I set up Multi-threading?

**URL:** <https://forums.unrealengine.com/t/how-do-i-set-up-multi-threading/281157>\
**Category:** Feedback & Requests\
**Tags:** threads, multithreading, unreal-engine, documentation, CPP, question\
**Created:** [April 20, 2014, 9:33pm UTC](https://forums.unrealengine.com/t/how-do-i-set-up-multi-threading/281157 "2014-04-20T21:33:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AutumnPyrri](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AutumnPyrri](https://forums.unrealengine.com/u/AutumnPyrri)\
**Post date:** [April 20, 2014, 9:33pm UTC](https://forums.unrealengine.com/t/how-do-i-set-up-multi-threading/281157/1 "2014-04-20T21:33:43Z")

</div>

Hello,

I was looking for a way to multi-thread so my world generation could continue during runtime, but I cant find a single thing on multi-threading in UE4 anywhere. Can someone point me where to look or give me some tips on how to do it?

Thanks!  
~Adam

---

<div class="post-metadata">

**Author:** ![gmpreussner\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gmpreussner\_1](https://forums.unrealengine.com/u/gmpreussner_1)\
**Post date:** [April 21, 2014, 5:51pm UTC](https://forums.unrealengine.com/t/how-do-i-set-up-multi-threading/281157/2 "2014-04-21T17:51:18Z")

</div>

You probably want to check out _FRunnable_ and _FRunnableThread_. _FRunnable_ encapsulates a worker that does the actual work. You inherit from this class, then implement the _Run()_ method (and possibly others, such as _Init()_, _Stop()_ and _Exit()_). You can then create a thread that uses this worker with _FRunnableThread::Create()_. You should be able to find many examples in the code base.

We have some other multi-threading mechanisms in the Engine, but your use case may not be a good fit. If your units of work are very small, you can take a look at the Task Graph system, which provides a nice way of performing task based multi-threading, and which is particularly useful if your tasks have dependencies to each other. You can find some usage examples by searching for _CreateTask()_ in the code base.

Please note that the UObject sub-system is currently not thread-safe, so depending on what you’re trying to do for world generation, you have to be extremely careful and know what you’re doing 🙂

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [April 22, 2014, 4:30am UTC](https://forums.unrealengine.com/t/how-do-i-set-up-multi-threading/281157/3 "2014-04-22T04:30:17Z")

</div>

#Thank you GmPreussner

Inspired by your answer I have tested and composed a Wiki Tutorial on using the Task Graph system!

#My Wiki Tutorial on Multi-Threading

I am including my entire source code! (Legal: I wrote all of it)

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

#Video

I am computing the first 50,000 prime numbers in the background while I continue to play around in the main game thread!

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

🙂

Rama
