Sign In Register

How can we help you today?

Start a new topic
Answered

Thread Safe

How can i make my cloud code thread safe? is there any lock mechanism for part of code?


Best Answer

Spark.LockKey :-) it says;


Creates a lock on an arbitrary key. Whilst the script ‘owns’ this lock no other script can lock on the same key, and will be blocked until the lock is released.


if 2 players call the same script at the same time will just one of them get this lock? it looks lock is per script, it is not per thread/request. Or i misunderstand it because of my poor English.


2 people have this question

Answer

Spark.LockKey :-) it says;


Creates a lock on an arbitrary key. Whilst the script ‘owns’ this lock no other script can lock on the same key, and will be blocked until the lock is released.


if 2 players call the same script at the same time will just one of them get this lock? it looks lock is per script, it is not per thread/request. Or i misunderstand it because of my poor English.

I have a question regarding Spark.LockKey()

This locks the key per request or provides a unique mutex? I mean, does the lock fail when I try to get it twice in the same script?

Sorry to answer myself.

 

var mutex = Spark.lockKey("foo", 0);
var mutex2 = Spark.lockKey("foo", 0);

 In this case both mutex variables are true.

Login to post a comment