Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7754029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:12:15+00:00 2026-06-01T12:12:15+00:00

To execute a loop in parallel I am using: int testValues[16]={5,2,2,10,4,4,2,100,5,2,4,3,29,4,1,52}; parallel_for (1, 100,

  • 0

To execute a loop in parallel I am using:

int testValues[16]={5,2,2,10,4,4,2,100,5,2,4,3,29,4,1,52};
parallel_for (1, 100, 1, [&](int i){ 
    int var1;
    for (var1=1; var1<=20000; var1++) {
        int var2, var3, var4;
        double u[45],pl;
        int values[16]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
        /* ... */
        for (var4=0; var4<16; var4++) {
            if (values[var4] != testValues[var4]) break;
        }
        /* ... */
    }
}

Can I be sure that all variables defined inside the parallel_for block (i.e. var1, var2, var3, var4, u, pl, values) will have scope local to each loop iteration, i.e. will not be shared across threads or loop iterations?

Also, is it safe for multiple threads to access testValues like this as long as they are only reading (not writing to it)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:12:16+00:00Added an answer on June 1, 2026 at 12:12 pm

    All variables inside the lambda are local to the thread which executes it, so yes they are safe.

    Reading/writing from/to the testValues array is theoretically a racecondition but if you are making sure that you are only reading and not writing at the same time or only write to different parts of the array it should be safe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Visual Studio 2010 Beta 2. In Parallel.For loop I execute the
I have a time consuming loop I would like to execute in parallel. Pseudocode:
I'm writing a script and I need to create a loop that will execute
I recently changed a For Each loop to a Parallel.ForEach loop. I'm concerned about
Supposing I have the following script <div id=something> <?php // execute a loop ?>
I have 100+ child packages and I need to run them in parallel from
Is there a way to loop over multiple lists in parallel in a makefile
I have a Parallel.ForEach() async loop with which I download some webpages. My bandwidth
I have to Execute Foreach loop Container in SSIS , for the list of
in While() ,How to skip the following nested statements and execute next loop of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.