Server-side variables for mutexes

Is there a way to have server-side variables in Space Lua? I am modifying the Git library and one issue I wanted to avoid was race conditions if the same instance is being browsed in multiple tabs, browsers and devices. The only way I can think of to do this is a mutex implemented using server-side state, but I am unable to figure out how to do this.

(BTW, my current modification to Git.md is here, in case it’s useful to someone: git.md · GitHub)

The only solution that comes to mind for me is writing whatever you need to a file and syncing that file.

Space Lua doesn’t support server-side variables, so true mutexes aren’t possible. File-based locking isn’t safe and therefore not reliable.

Adding a small API to SilverBullet for locking could work, but as of now, that functionality doesn’t exist.

I would agree with

File-based locking isn’t reliable and therefore not safe.

, but ultimately it amounts to the same thing: files are sh*t for this.

I guess your best bet is doing everything on the server, inside a bash script for example, but this is far from perfect.
A mutex api would probably make sense although I don’t think that’s trivial to implement, there are definitely some things to consider.

1 Like