• Artur Grunau's avatar
    Guard accesses to Lua state with a mutex · a337b188
    Artur Grunau authored
    Now that support for signals and slots has been added to Lua pipelines,
    each Lua state has to be protected with a mutex because it's not
    thread-safe and different threads (running LuaPipeline or a processor
    attached to it) may try to access it simultaneously.
    
    The mutex needs to be recursive due to the fact that Lua code can
    trigger the emission (or copying) of signals that have slots defined it
    Lua connected to them. This in turn causes the state to be accessed from
    a thread that, unbeknownst to it, already holds a lock on the mutex.
    
    A pointer to the mutex is stored in the state's registry; this way code
    that accesses Lua state directly (e.g. connections between sigslot's
    signals and slots defined in Lua) can retrieve and lock it when
    necessary.
    
    References #1
    a337b188