Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How many objects or references are associated with a block variable with static storage duration(in multi-thread)? #5349

Open
xmh0511 opened this issue Mar 18, 2022 · 1 comment

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Mar 18, 2022

void fun(){
  static int value = 0;
}
int main(){
   fun(); // in main thread
  /* fun(); assume in a different thread*/
 /* fun(); assume in a different thread*/
}

we lack the specification for the (block) variable with static storage duration in a similar manner as [class.static.data] p1 did for the static data member. The approach of [class.static.data] p1 is that:

If a static data member is declared thread_­local there is one copy of the member per thread. If a static data member is not declared thread_­local there is one copy of the data member that is shared by all the objects of the class.

The second sentence can imply that we only have one concrete object or reference associated with the static data member regardless of how many threads refers to it.

Don't we need a similar rule for other kinds of variables with static storage duration, non-normative, such as the following:

There is only one object or reference associated with the variable with static storage duration at any time.

@jensmaurer
Copy link
Member

Yes, we need a conceptual divorce between variable / data member (that appears in source code) and which object it denotes, which might be one (static non-thread_local), one per thread (thread_local), or one per function invocation (non-static local variable).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants