Jump to content
OMRON Forums

Can Sys.Lock[i] cause deadlocks?


Recommended Posts

I was searching for mutex lock support in the PMAC Script Language and stumbled across the Sys.Lock[i] variable in the user's manual. 

Per the "Power PMAC User’s Manual" version published May 15, 2019, it builds a case for the use of Sys.Lock[i] as a way to avoid incorrect register writes when two tasks occur concurrently operating at different priority levels (i.e. background PLC vs realtime PLC). In general, the example in the manual makes sense and appears to be working using some cursory tests.

However, I'm trying to determine if there's a risk of deadlocks when tasks running at different priorities reference the same Sys.Lock[i]. Here would be the scenario:

1. Background PLC successfully obtains Sys.Lock[1] and begins running critical section.

2. While Background PLC is in possession of lock, Realtime PLC interrupts and attempts to grab Sys.Lock[1]

3. The Realtime PLC uses the convention "while (Sys.Lock[7] == 1) {} " and spins while waiting for the lock to be available.

4. Because the Realtime PLC is stuck in a loop waiting, the Background PLC never gets enough time to finish the critical section and release the lock.

5. We're now stuck in deadlock where Realtime PLC is waiting on Background PLC to finish, but Background PLC is waiting for Realtime PLC to finish since it's at a higher priority.


Is this a valid scenario/concern? I guess I'm hoping it's not, but it seems like it would be based on my understanding on how tasks are scheduled on the PMAC. Any clarification would be appreciated!



Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

I don’t think the “Process Locking” feature is your issue. With the suggested usage of the Sys.Lock[] element, the “clearing” of the lock would be within a few scans of the PLC.

My educated guess is something else in the PLC is “holding” up the execution.

Contact ODT's direct technical support with your full issue details at: ODT-Support@Omron.com

Link to comment
Share on other sites

Hi Steve, thanks for sharing the updated manuals.

I'm actually not experiencing any lock-ups currently, I'm just curious if the scenario I describe would put my application at risk. Essentially - if a realtime PLC were to get stuck in a loop waiting for a lock to be released, would a background PLC in possession of the lock be able to progress and release the lock? or would the realtime PLC starve all available resources?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...