fix: Fixes hanging tests (#1535)

This commit is contained in:
Kamron Batman 2023-10-09 00:22:59 -07:00 committed by GitHub
parent d0d81d0d5f
commit 629a5008c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 4 deletions

View file

@ -383,11 +383,11 @@ public static class World
}
}
internal static void SleepSerializationThreads()
public static void ExitSerializationThreads()
{
for (var i = 0; i < _threadWorkers.Length; i++)
{
_threadWorkers[i].Sleep();
_threadWorkers[i].Exit();
}
}
@ -524,6 +524,7 @@ public static class World
private readonly AutoResetEvent _startEvent; // Main thread tells the thread to start working
private readonly AutoResetEvent _stopEvent; // Main thread waits for the worker finish draining
private bool _pause;
private bool _exit;
private readonly ConcurrentQueue<IGenericSerializable> _entities;
public SerializationThreadWorker()
@ -546,6 +547,13 @@ public static class World
_stopEvent.WaitOne();
}
public void Exit()
{
_exit = true;
Wake();
Sleep();
}
public void Push(IGenericSerializable entity)
{
_entities.Enqueue(entity);
@ -576,7 +584,7 @@ public static class World
worker._stopEvent.Set(); // Allow the main thread to continue now that we are finished
worker._pause = false;
if (Core.Closing)
if (Core.Closing || worker._exit)
{
return;
}