"...content/tools/Touch.Server.exe" did not exist on "92c5a9fae79fdbc8957b737ee583e0b2a22d9e00"
Unverified Commit 8a34d2f4 authored by Vinicius Jarina's avatar Vinicius Jarina Committed by GitHub
Browse files

Use `ConcurrentQueue` due a race condition. (#311)

parent be037f73
......@@ -2,6 +2,7 @@
using System.IO;
using System.Reflection;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Runtime.InteropServices;
using KeraLua;
......@@ -50,7 +51,7 @@ namespace NLua
// object # to object (FIXME - it should be possible to get object address as an object #)
readonly Dictionary<int, object> _objects = new Dictionary<int, object>();
readonly Queue<int> finalizedReferences = new Queue<int>();
readonly ConcurrentQueue<int> finalizedReferences = new ConcurrentQueue<int>();
internal EventHandlerContainer PendingEvents = new EventHandlerContainer();
MetaFunctions metaFunctions;
......@@ -1136,11 +1137,10 @@ namespace NLua
if (finalizedReferences.Count == 0)
return;
while (finalizedReferences.Count != 0)
{
int reference = finalizedReferences.Dequeue();
int reference;
while (finalizedReferences.TryDequeue(out reference))
state.Unref(LuaRegistry.Index, reference);
}
}
}
}
......@@ -2384,7 +2384,7 @@ namespace NLuaTest
void PleaseRunFinalizers()
{
for (int i = 0; i < 20; i++)
for (int i = 0; i < 40; i++)
{
GC.Collect();
GC.WaitForPendingFinalizers();
......@@ -2412,6 +2412,7 @@ namespace NLuaTest
ImplicitlyCreateATable(lua);
lua.State.GarbageCollector(LuaGC.Collect, 0);
lua.State.GarbageCollector(LuaGC.Collect, 0);
int after2 = lua.State.GarbageCollector(LuaGC.Count, 0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment