Question on variables in a parallel gateway flow

I had a question on how variables are handled in a parallel gateway (fork and join)
If we have a parallel gateway, lets say with just 1 incoming sequence flow and then forking into 3 sequence flows from the parallel gateway and in the end joining the 3 flow into 1 flow again
If the tasks on the 3 sequence flows change/set the same global variables, how does the join handle this. For example in the above flow, if I have a global variable called “globalVar” and this is modified by 3 tasks in the 3 sequence flows respectively, how does the join (after the tasks) take place on the parallel gateway?
Does it pick any random value out of the 3?

When you call #setVariable, the variables overwrite each other at the time of calling this method. When you call #setVariableLocal, all of them are discarded when the parallel join is triggered (with exceptions in certain circumstances, but this is the baseline you should rely on).


@thorben Could you please elaborate under which circumstances the variables are not discarded when the parallel join is triggered?
Thank you.