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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:20:04+00:00 2026-06-17T19:20:04+00:00

I have a thread local variable envptr and variable that is not thread-local also

  • 0

I have a thread local variable envptr and variable that is not thread-local also called envptr. The latter variable is only used in a single thread whose running code does not see the thread-local variable declaration. The thread-local variable is used by different threads, each of which do not see nor need to see the declaration of the non-thread-local variable.

Is this scenario possible and produces defined behavior? I am using linux 32bit and 64bit on x86.

  • 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-17T19:20:05+00:00Added an answer on June 17, 2026 at 7:20 pm

    Are they the same variable, or not? In other words, what is
    their linkage?

    If it is external, then no. If it is internal, then it’s OK unless the two definitions both occur in the same file.

    If there is no linkage, then there is no problem.

    Unless I’ve overlooked something, thread_local has no impact on linkage, so the usual rules apply (and defining the variable thread_local in one translation unit, and not in another, is a violation of the one-definition rule).

    I think there’s a bug in the standard here, however. The
    standard (§7.1.1/1) says that “If thread_local appears in any
    declaration of a variable it shall be present in all
    declarations of that entity.” There’s no explicit statement
    that a diagnostic is not required, or that violation of this
    rule is undefined behavior, so a compiler is required to
    diagnose the error. Except that, of course, if you define at
    namespace scope:

    thread_local int i;
    

    in one translation unit, and:

    int i;
    

    in another, then the compiler probably can’t diagnose the error
    (and I’m fairly sure the committee didn’t want to require it).
    My guess is that the intent here is undefined behavior.

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

Sidebar

Related Questions

I have a local thread that is started on button-click event from the main
I have a Dllmain that allocates Thread local storage when a thread attaches to
I have a thread from a thread pool in a service that does quite
I have a thread in Ruby. It runs a loop. When that loop reaches
Is ResultSet Thread safe? My question arises because in my program i have used
I have a variable in my function that is static, but I would like
Can anyone tell me if I'm right or not? I have two thread which
Is there a good, platform-agnostic way to implement a variable that's local to both
With normal instance methods, local variables are thread safe. If I have the following
I have declared some local variable in one function like this: void* thread_function (void*

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.