C++ Lua ThreadSafe
<p>I have some problems with <code>c++</code> &amp; <code>lua</code> threading.<br>
My project is loading <code>.lua</code> files to single <code>Lua_State</code> (need for their synergy). Also, it adds some LuaRefs to vector to use it later in callbacks.<br>
The only problem I currently have is <code>no TheadSafe</code>. I've tried to create <code>mutex</code> objects and lock them before calling each of vector -> then unlocking...</p>

<p>For Example: </p>

<pre><code>std::vector&lt;luabridge::LuaRef&gt; drawCall;
void OnDraw()
{
    try { for (luabridge::LuaRef f : drawCall) f(); } 
    catch (luabridge::LuaException ex) { Msg(ex.what()); }
}
void AddDrawCall(luabridge::LuaRef obj) { if (!obj.isNil()) drawCall.push_back(obj); }
</code></pre>

<p>Where <code>AddDrawCall</code> is called from lua and adding function to <code>drawCall</code> as LuaRef.<br>
<code>OnDraw()</code> is called from another thread using <code>detoured</code> function.<br>
With global mutex I have huge performance drop -> Blinking drawings, etc.<br>
Btw I have seen that there are other solutions: Calling <code>lua_newthread</code> or creating several <code>Lua_State</code>s but have no idea how to do it with this callbacks :(</p>