Page 1 of 1

"Thread safe" task

Posted: Tue Feb 05, 2013 5:54 am
by Vara04
It would be interesting tasks initiated from another task (with Start Task) runs in its
context and independently.
This is to have no deadlocks between tasks.

Example of use:
I do a common task that makes a series of operations with parameters.
I called this task in various other tasks that I do not control the trigger.
Currently, if two tasks require the common task of the two tasks lock.

So ideally, it should be that each can perform the common task of its own.

"Thread safe" task

Posted: Tue Feb 05, 2013 9:00 am
by Oleg
You can get deadlock effect when tasks waits each other infinite.
Suppose Task1 starts Task2 with waiting and Task2 starts Task1 with waiting.
Task1 waits Task2, and Task2 waits Task1. This is deadlock.

Your example:
Task1 starts CommonTask
Task2 starts CommonTask

If you want to guarantee that CommonTask will performed for each caller you should start CommoTask so:
Wait CommonTask
Start CommonTask with waiting

Wait For task waits until the task finished.
If CommonTask is not running then Wait For task will not wait.
In this case CommonTask will performed for each caller.

I can send you small examples if it's necessary

Re: "Thread safe" task

Posted: Tue Mar 31, 2015 11:27 pm
by Denli
Oleg wrote: I can send you small examples if it's necessary
example please

Re: "Thread safe" task

Posted: Wed Apr 01, 2015 9:57 am
by Oleg
Import these 3 tasks, please:
WaitForTaskExample.zip
(1.97 KiB) Downloaded 2533 times

Re: "Thread safe" task

Posted: Wed Apr 01, 2015 11:28 am
by Denli
Example helped me :D Thank you so much!

Re: "Thread safe" task

Posted: Fri May 13, 2016 12:37 pm
by Vara04
Yes but :
- if the commonTask must be call by a lot of tasks
- and the common task run during "long time",
all tasks are waiting... and there is a risk that at least, 2 tasks launch commonTask at the same time after waiting :D

For the moment I copy all steps in all tasks :roll: