On 3/6/18 9:42 AM, Shachar Shemesh wrote:

I fail to see any reasoning[1] that disallows the former but allows the later.


1 - That is obviously not true. I see the reasoning all too well. Static vars are like globals, and you're not getting to them via the struct's instance. I would argue that, as far as the programmer, however, there is no difference. There is no semantic difference between allowing the first and not the second.

These aren't globals or static, they are no different than pointers (which is actually what they are).

Here is the problem with option 2: If you have a struct that is immutable (or shared), it can be passed without problems to another thread. If you can then start mucking with local variables in another thread with the assumption that they are thread-local, then you have broken the guarantee of immutable or shared. Even const can cause problems.

static data is different, in that it is either shared or thread-local, and then the path forward is quite clear. Passing thread-local data to another thread as if it were local to the recipient is like __gshared, and shouldn't be so easy to do.

-Steve

Reply via email to