This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

How to lock a script during execution?
#1
Hi,
 
In a project, we use a pushbutton on KNX which triggers a LM4 script that gives instruction to the intercom to give a doorbell sound. But… when they push more than 1 time (like a couples of times directly after eachother), the intercom gets a couple of times the instruction and gets confused.
 
What is the best way to avoid that a running script is executed a second time?
 
Thanks!
Reply
#2
You can use storage to save last script execution time.
This example allows a script to be executed once in 5 seconds, you can tune the timer value as required:
Code:
now = os.time()
prevsend = storage.get('prevsendtime', 0)
delta = now - prevsend

if delta < 0 or delta > 5 then
  storage.set('prevsendtime', now)
  alert('executing script')
end

Another advanced approach is to lock any event script from executing in parallel by using semaphores:
http://openrb.com/docs/semaphore.htm
Reply
#3
Can disabling and enabling the script work? So, at the first line of the script "disable" itself and at the last line "enable" itself?
Reply
#4
That will introduce race condition and it will fail from time to time. The only guaranteed way is to use semaphores.
Reply


Forum Jump: