Let's imagine the following hypothetical situation:
. "This is the control robot" : "dowork" . "Something here" send "worker" to "increment" wait for 1 goto "dowork" end
Then, we have the following worker robot:
end : "increment" lockself inc "important_counter" by 1 unlockself end
As you may guess, the lockself and unlockself act as mutexes in this context. Without them, you could have concurrent control robots mess up "important_counter"'s result.
However, let's suppose that when two calls to the worker robot happened simultaneously, you didn't want to simply have one of them not work, and be ignored (as would happen with the above code) and instead want to force the controller robot that called it to wait until the worker is done, then sending the worker to its job again?
Right now, you'd need to do something like this:
. "This is the control robot" : "dowork" . "Something here" : "tryworker" wait for 1 if "w_busy" > 0 then "tryworker" send "worker" to "increment" wait for 1 goto "dowork" end
Worker:
set "w_busy" to 0 end : "increment" set "w_busy" to 1 lockself inc "important_counter" by 1 unlockself set "w_busy" to 0 end
My suggestion would turn that code into this, sparing a counter and a few lines of code, for readability (making it more humanly comprehensible):
. "This is the control robot" : "dowork" . "Something here" : "tryworker" wait for 1 send "worker" to "increment" else "tryworker" wait for 1 goto "dowork" end
end : "increment" lockself inc "important_counter" by 1 unlockself end
I get that it might not be that important of a change in the long run, but I thought it might be useful to more people out there. In fact, if anyone has suggested this before, I apologize, but the search function didn't appear to be working so I could not check for that.