This fix worked great for a long time for me but at one point some of the multithreaded part of my project started to crash the game.It tried to read incomplete http request. It did not happened on the binary version of the engine so I guess it was because of this PRAGMA_DISABLE_OPTIMALIZATION fix.
And as mentioned before in this thread I can also confim that this happens on ASUS hardware. It occured on my PC with ASUS Prime B650 Plus motherboard. On my friend’s Asus laptop and on one of the office PC also with asus motherboard.
At first I fixed it with putting volatile qualifiers inside FHttpThread::Run()
uint32 FHttpThread::Run()
{
// Arrays declared outside of loop to re-use memory
TArray<IHttpThreadedRequest*> RequestsToCancel;
TArray<IHttpThreadedRequest*> RequestsToComplete;
while (!ExitRequest.GetValue())
{
if (ensureMsgf(!bIsSingleThread, TEXT("HTTP Thread was set to singlethread mode while it was running autonomously!")))
{
const /*volatile*/ double OuterLoopBegin = FPlatformTime::Seconds();
/*volatile*/ double OuterLoopEnd = 0.0;
bool bKeepProcessing = true;
while (bKeepProcessing)
{
const /*volatile*/ double InnerLoopBegin = FPlatformTime::Seconds();
Process(RequestsToCancel, RequestsToComplete);
if (RunningThreadedRequests.Num() == 0)
{
bKeepProcessing = false;
}
const /*volatile*/ double InnerLoopEnd = FPlatformTime::Seconds();
if (bKeepProcessing)
{
SCOPE_CYCLE_COUNTER(STAT_HTTPThread_ActiveSleep);
double InnerLoopTime = InnerLoopEnd - InnerLoopBegin;
double InnerSleep = FMath::Max(HttpThreadActiveFrameTimeInSeconds - InnerLoopTime, HttpThreadActiveMinimumSleepTimeInSeconds);
FPlatformProcess::SleepNoStats(InnerSleep);
}
else
{
OuterLoopEnd = InnerLoopEnd;
}
}
SCOPE_CYCLE_COUNTER(STAT_HTTPThread_IdleSleep)
double OuterLoopTime = OuterLoopEnd - OuterLoopBegin;
double OuterSleep = FMath::Max(HttpThreadIdleFrameTimeInSeconds - OuterLoopTime, HttpThreadIdleMinimumSleepTimeInSeconds);
FPlatformProcess::SleepNoStats(OuterSleep);
}
else
{
break;
}
}
return 0;
}
That fixed the issue but I’ve read that volatile qualifier is not really safe for multithreaded applications.
So my second fix was to change FWindowsPlatformTime::Seconds(), ::Cycles() and ::Cycles64 to regular functions (removed FORCEINLINE).
Both fixes worked on their own. I think second one is more elegant. Feel free to use them as you want. You can combine them just to be extra safe