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 6019681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:27:23+00:00 2026-05-23T03:27:23+00:00

I know that that question may be seemed as a duplicate, but I haven’t

  • 0

I know that that question may be seemed as a duplicate, but I haven’t got the answer reading the other questions.

My situation – Visual C++ compiler 2005 from express edition studio + Windows sdk.

Just a question if a function like that:

void myFunc()
{
    int i=0;
    i++;
}

is safe to call from multiple threads?

Yes, it seems like it is, but won’t the compiler make the i variable be static in the memory? So that could lead to that two threads are acting together on one memory region? Or my fears are just some fears of a fool? And all local variables are created in the moment of calling the function?

  • 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-05-23T03:27:24+00:00Added an answer on May 23, 2026 at 3:27 am

    Yes, it is thread safe.

    i will not be static in memory, because it is not static. If, on the other hand, you had written:

    void myFunc()
    {
        static int i = 0;
        i++;
    }
    

    Then it would not be thread safe (well, if i was actually used).

    Local variables are all located on the stack (or live entirely in registers). Each thread has its own stack, and registers are handled in such a way that they are essentially local to each thread (see Context Switching), so you are fine.

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

Sidebar

Related Questions

I know that this may be an amateur question but for some reason I
I know that my this question may sound pathetic to you but as a
I realise that this question may be almost impossible to answer definitively, but: Is
I'm aware that this question may have been asked before, but I still haven't
I know that this question may be closed by some of you, but my
I know that this may seem as a question that was already asked, but
I know that similar question was asked several times, but still I can't make
I know that my question will be very similar to other ones already asked
I know that this is a simple question for PHP guys but I don't
i know that there isn't code inside my question, but i think this is

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.