# Two threads are not work simultaneously

**URL:** <https://forums.unrealengine.com/t/two-threads-are-not-work-simultaneously/73710>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [September 15, 2016, 3:09pm UTC](https://forums.unrealengine.com/t/two-threads-are-not-work-simultaneously/73710 "2016-09-15T15:09:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Syntopia](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Syntopia](https://forums.unrealengine.com/u/Syntopia)\
**Post date:** [September 15, 2016, 3:09pm UTC](https://forums.unrealengine.com/t/two-threads-are-not-work-simultaneously/73710/1 "2016-09-15T15:09:18Z")

</div>

Hello,

I need to create two threads. Whan I do it, I get a warning message in the log:

**LogStats:Warning: MetaData mismatch. Did you assign a stat to two groups? New //STATGROUP\_Threads//FTCPSocketListeningTh///Thread\_2130\_0///####STATCAT\_Advanced#### old //STATGROUP\_Threads//FTCPSocketListeningTh///Thread\_202c\_0///####STATCAT\_Advanced####**

And my second thread dont stop opposed to in the first. I read in answers, it because of the threads same name, but I called it different.

Help me fix it. Thanks!

Template сode of my two almost identical FRunnable class: FServerStatusCheckingTh and FTCPSocketListeningTh  
Threads just display a message in the log every second. Base on:

> **[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...

.h

```auto

#pragma once
 
 class SIENNACLIENTPROJECT_API FServerStatusCheckingTh : public FRunnable
 {
     static FServerStatusCheckingTh* Runnable;
 
     FRunnableThread* Thread;
 
 public:
 
     FServerStatusCheckingTh();
     ~FServerStatusCheckingTh();
 
     virtual bool Init();
     virtual uint32 Run();
     virtual void Stop();
 
     static FServerStatusCheckingTh* RunServerChecking();
 
     static bool bThreadRun;
 
     static void Shutdown();
 
 };

```

.cpp

```auto

#include "SiennaClientProject.h"
 #include "ServerStatusCheckingTh.h"
 
 FServerStatusCheckingTh* FServerStatusCheckingTh::Runnable = NULL;
 bool FServerStatusCheckingTh::bThreadRun = false;
 
 FServerStatusCheckingTh::FServerStatusCheckingTh()
 {
     Thread = FRunnableThread::Create(this, TEXT("ServerStatusChecking"), 0, TPri_BelowNormal); 
 }
 
 FServerStatusCheckingTh::~FServerStatusCheckingTh()
 {
     delete Thread;
     Thread = NULL;
 }
 
 bool FServerStatusCheckingTh::Init()
 {
     bThreadRun = true;
     return true;
 }
 
 uint32 FServerStatusCheckingTh::Run()
 {
     while (bThreadRun)
     {
         FPlatformProcess::Sleep(1.f); 
     GLog->Log("FServerStatusCheckingTh");
         
     }
     return 0;
 }
 
 void FServerStatusCheckingTh::Stop()
 {
 }
 
 FServerStatusCheckingTh* FServerStatusCheckingTh::RunServerChecking()
 {
     if (!Runnable && FPlatformProcess::SupportsMultithreading())
     {
         Runnable = new FServerStatusCheckingTh();
     }
     return Runnable;
 }
 
 void FServerStatusCheckingTh::Shutdown()
 {
     if (Runnable)
     {
         bThreadRun = false;
 
         delete Runnable;
         Runnable = NULL;
     }
 }

```

.h

```auto

#pragma once
 
 class SIENNACLIENTPROJECT_API FTCPSocketListeningTh : public FRunnable
 {
     static FTCPSocketListeningTh* Runnable;
 
     FRunnableThread* Thread;
 
 public:
 
     FTCPSocketListeningTh();
     ~FTCPSocketListeningTh();
 
     virtual bool Init();
     virtual uint32 Run();
     virtual void Stop();
 
     static FTCPSocketListeningTh* RunSocketListening();
 
     static bool bThreadRun;
 
     static void Shutdown();
 
 };

```

.cpp

```auto

 #include "SiennaClientProject.h"
 #include "TCPSocketListeningTh.h"
 
 FTCPSocketListeningTh* FTCPSocketListeningTh::Runnable = NULL;
 bool FTCPSocketListeningTh::bThreadRun = false;
 
 FTCPSocketListeningTh::FTCPSocketListeningTh()
 {
     Thread = FRunnableThread::Create(this, TEXT("TCP_SocketListening"), 0, TPri_BelowNormal); 
 }
 
 FTCPSocketListeningTh::~FTCPSocketListeningTh()
 {
     delete Thread;
     Thread = NULL;
 }
 
 bool FTCPSocketListeningTh::Init()
 {
     bThreadRun = true;
     return true;
 }
 
 uint32 FTCPSocketListeningTh::Run()
 {
     while (bThreadRun)
     {
         FPlatformProcess::Sleep(1.f);
         GLog->Log("FTCPSocketListeningTh");
     }
     return 0;
 }
 
 void FTCPSocketListeningTh::Stop()
 {
 }
 
 FTCPSocketListeningTh* FTCPSocketListeningTh::RunSocketListening()
 {
     if (!Runnable && FPlatformProcess::SupportsMultithreading())
     {
         Runnable = new FTCPSocketListeningTh();
     }
     return Runnable;
 }
 
 void FTCPSocketListeningTh::Shutdown()
 {
     if (Runnable)
     {
         bThreadRun = false;
 
         delete Runnable;
         Runnable = NULL;
     }
 }

```

I call Run and Shutdown of threads in GameInstance:

```auto

 void USiennaGameInstance::Init()
 {
     GLog->Log("<<< USiennaGameInstance::USiennaGameInstance >>>");
 
         FServerStatusCheckingTh::RunServerChecking(); 
     FTCPSocketListeningTh::RunSocketListening();
 }
 
 void USiennaGameInstance::Shutdown()
 {
     FTCPSocketListeningTh::Shutdown();
     FServerStatusCheckingTh::Shutdown();
 }

```

---

<div class="post-metadata">

**Author:** ![Syntopia](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Syntopia](https://forums.unrealengine.com/u/Syntopia)\
**Post date:** [September 16, 2016, 10:10am UTC](https://forums.unrealengine.com/t/two-threads-are-not-work-simultaneously/73710/2 "2016-09-16T10:10:12Z")

</div>

Solved, I called a function to create a threads multiple times) eventually create a threads with the same name.

Morality of story: in any strange situation, go to sleep)
