How to prevent retriggering a task?

Hi, I have a task, waiting for a trigger signal. After that some processing starts out, which also contains waiting phases, but on other semaphores. After work is finished, the task waits again for a trigger. How can I effectively prevent retriggering. The problem is, that I have to set some parameters before the trigger is set, if I don’t prevent retriggering, this changes corrupt the running sequence. Task skeleton: task { take (smphrtrigger); FOREVER { Take(smphrtrigger); //Do something } } void triggerTask() { xy = 4711; Give(smphr_trigger); } Thanks for helping With best regards Gerhard

How to prevent retriggering a task?

I dont understand. If the code is looping and taking the semaphore each loop like you show then the take will time out or return when the semaphore is given. If you dont want that then is the answer just not to take the semaphore?

How to prevent retriggering a task?

.. the loop needs some time. Guess //Do something is running for 200ms. In this time, it should be forbidden to make any changes. So calling the trigger function, which sets some parameters should be prevented. Only after the task is back waiting for a trigger calls to the trigger function should be allowed.

How to prevent retriggering a task?

It sounds like you need to wrap the acces to the data with a mutex, so the triggered task begins with taking the mutex, and gives it when done, and the trigger action takes the mutex before setting up the data and then gives it when triggering the task. An alternative (if you aren’t sending much data) is put it in a struct and rather than using a semaphore, send the data in a queue, and have sender and receiver each keep private copies so they can’t corrupt each other.

How to prevent retriggering a task?

Thanks. As the point in time has to be exect as possible (trigger), a queue isn’t that good idea, so I choose to use a mutex With best regards Gerhard

How to prevent retriggering a task?

The Queue will have practically the same timing as the semaphore. Assuming the processing task is waiting on a queue get (like it was waiting for a semaphore take), as soon as the sending task does a queue send (instead of a semaphore give) the processing task will become ready, and if of higher priority switched to, just like the case of the semaphore. The one difference will be that if the values sent need to be computed just before the task starts (which you do not currently maintain, which is part of the issue you are having), then the Mutex wi be better as you can’t get the Mutex until the processing task is basically done.