KBEC-00056 - Implementing semaphores or a locking mechanism, using Commander primitives as a mutex or token

Article ID:360033194711
1 minute readKnowledge base


"incrementProperty" is an atomic operation in ElectricCommander. At this time, it is the only property operation that is atomic. If you need to do something more complex, but do it safely in a controlled environment under Commander, there are two implementation methods:


Use a property as a "token" or "mutex"

  1. Initialize it to "0"

  2. Increment it using incrementProperty

  3. If the value is "1", hold the token, otherwise, delay and try again

  4. Do your "protected" operation

  5. Set the property to "0"

  6. Be careful if this spans multiple jobs because your job could be aborted while you hold the token.

Use a special resource as a mutex

  1. Define a resource (on an existing agent) to use for this purpose

  2. Set the resource step limit to "1"

  3. Whenever you need to do a protected operation, set the step to use this resource