How to communicate save between different task classes AsSem

Because of the fact that the AutomationRuntime has a task system it means, every program can be interrupted during the runtime, also in the middle of the execution, this means we can have a producer and consumer problem.
I can Imagine that for this case the library AsSem is available.
Unfortunately in the with AutomationStudio delivered example, it is only shown one task not both, so I am not pretty sure how to handle the function block to save for example a global variable.

The SemCreate ident must be shared globally between the two tasks which communication between each other right?

So one task create the semaphore with SemCreate_0 and SemCreate is locally defined in that task memory. After that this task writes the Ident to a global variable.
Is that right and a good idea?

Is there any case that a semaphore gets deleted of a program transfer?
Or does the delete 100% only happen with the function block SemDelete?

Hi,

Yes, if you want to use the same semaphore in different tasks (for example to control the access into critical code sections for handling shared ressources - I assume that’s the usecase you’re talking about), you have to share the ident from SemCreate() to all of the tasks they want to use SemAcquire() and SemRelease().

As I know, SemCreate() uses native Automation Runtime semaphores (I mean semaphores with a operating system-wide scope), so I can’t imagine that they’re deleted by a program transfer. I assume they’re really only delete by reboot or by SemDelete()… but to be honest, I haven’t had a closer look into it until today.

Best regards!

Hi again,

because I was curious, I did a short test → in a nutshell: it works like expected.

What I tried:

  • task1 that creates the semaphore und stores the ident in a global var
  • tasks2 and task3 using the semaphores ident
  • after installation, checked if the semaphore was created successfully and checked acquiring and releasing
  • then, deleted task1 from the PLC (by removing from deployment list and transferring)
  • task2 and task3 still were able to access the semaphore, even if the local SemCreate() instance from task1 wasn’t longer existing
  • after rebooting the PLC (task1 stayed removed), access to the semaphore wasn’t longer possible for task2 and task3

Best regards.