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 @@ ...@@ -2,6 +2,7 @@
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using KeraLua; using KeraLua;
...@@ -50,7 +51,7 @@ namespace NLua ...@@ -50,7 +51,7 @@ namespace NLua
// object # to object (FIXME - it should be possible to get object address as an object #) // 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 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(); internal EventHandlerContainer PendingEvents = new EventHandlerContainer();
MetaFunctions metaFunctions; MetaFunctions metaFunctions;
...@@ -1136,11 +1137,10 @@ namespace NLua ...@@ -1136,11 +1137,10 @@ namespace NLua
if (finalizedReferences.Count == 0) if (finalizedReferences.Count == 0)
return; return;
while (finalizedReferences.Count != 0) int reference;
{
int reference = finalizedReferences.Dequeue(); while (finalizedReferences.TryDequeue(out reference))
state.Unref(LuaRegistry.Index, reference); state.Unref(LuaRegistry.Index, reference);
}
} }
} }
} }
...@@ -2384,7 +2384,7 @@ namespace NLuaTest ...@@ -2384,7 +2384,7 @@ namespace NLuaTest
void PleaseRunFinalizers() void PleaseRunFinalizers()
{ {
for (int i = 0; i < 20; i++) for (int i = 0; i < 40; i++)
{ {
GC.Collect(); GC.Collect();
GC.WaitForPendingFinalizers(); GC.WaitForPendingFinalizers();
...@@ -2412,6 +2412,7 @@ namespace NLuaTest ...@@ -2412,6 +2412,7 @@ namespace NLuaTest
ImplicitlyCreateATable(lua); ImplicitlyCreateATable(lua);
lua.State.GarbageCollector(LuaGC.Collect, 0);
lua.State.GarbageCollector(LuaGC.Collect, 0); lua.State.GarbageCollector(LuaGC.Collect, 0);
int after2 = lua.State.GarbageCollector(LuaGC.Count, 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