Are Scripts Executed Single-Threaded ?

UPDATE: probably I’m completey wrong here. Can’t reproduce intermediate calls between A Start and A End anymore. Means state should always be in a consistent state. Think I misinterpreted some output. Maybe we can delete this post ?

Hi there,

I’m wondering if a Renoise LUA scripts is actually executed “single-threaded”. I assumed that but I’m facing the following concurrency problem:

-- global state  
mystate = 0  
function A()  
 print("A Start")  
 -- change my state here  
 print("A End")  
function on_idle()  
 -- change my state here  
function midi_callback()  
 -- change my state here  
-- Output is something like:  
-- A-start  
-- IDLE  
-- IDLE  
-- MIDI  
-- IDLE  
-- A-End  

Problem: state is in a non-consistent state during execution of A.
So I need a kind of mutex here. But if there are multiple threads involved then
I guess I would need something like synchronized functions or an explicit Renoise mutex which is thread-safe.
Otherwise I assume race-conditions will occur.

If it’s always the same single thread that just stops execution of A and jumps to idle or midi handler then I can use a simple global variable, right ?

Just to answer the question: Yes, all Lua scripts, tools, callbacks, everything you’re able to access via Lua in Renoise are right now !always! executed in one thread only: Renoises UI thread. Everything else would be unmaintainable.

At some point we’ll also allow scripts in the realtime threads, but then we will guarantee that a scripts get only called in either the realtime or the UI thread, in order to avoid that scripts have to deal with concurrency problems.

thanks for the info. Interesting how you split it up into realtime and GUI. Makes totally sense to me !