cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Kran
Helper IV
Helper IV

Is concurrenct thread safe in PowerAutomate?

If I set a variable with a value within a loop and then turn on concurrency - will it be thread safe?

Or can one thread change the value of the variable which will affect another thread?

 

Is there a recommendation to avoid concurrency when we set variables within the loop? Is there any workaround?

6 REPLIES 6
tom_riha
Super User
Super User

Hello @Kran ,

if you use variable in a parallel loop, all the parallel runs will access it at the same time. It's ok if you only read the variable, but if you also update it, it'll be a mess.

If it's possible, you can use a 'Compose' action instead of a variable, each parallel branch will have its own 'Compose' action with its own input/output.



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]
Kran
Helper IV
Helper IV

@tom_rihaThanks for your reply! That was very good information!

 

But how can I set a variable inside a compose action?

 

In my situation, as of now, I have a SWITCH case, where I for each of the cases, set a variable which is then used to set a column on a new record.

 

duration2.png

 

Do you see anyway to solve this with a compose action? Thanks!

 

v-xiaochen-msft
Community Support
Community Support

Hi @Kran ,

 

You could use 3 compose actions or create 3 variables to solve it.

 

vxiaochenmsft_0-1640593528586.png

 

 

Best Regards,

Wearsky

Kran
Helper IV
Helper IV

thanks for your reply!
So that If statement checks whether the first condition is empty? And if is, then it checks next one?

v-xiaochen-msft
Community Support
Community Support

Hi @Kran ,

 

Please use  switch conditions in your If expression .

Flow needs to know which compose action to use .

 

Best Regards,

Wearsky

Hello @Kran ,

I was thinking about the problem and I wrote a blog post with my solution: https://tomriha.com/using-variable-in-a-parallel-loop-in-power-automate-flow/.

Use an array variable, instead of the 'Set variable' use 'Append to array variable' while including some unique identifier of each item + the corresponding value. Filter only the corresponding value from the array and use it in the 'Add row...' action.

 



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Top Solution Authors
Top Kudoed Authors
Users online (1,896)