How come a thread can access another thread's stack variable?

Andrej Mitrovic andrej.mitrovich at gmail.com
Tue Nov 22 14:00:17 PST 2011


import core.thread;
import std.stdio;

struct Foo
{
    int field;
    void test()
    {
        writeln("field: ", &field);
    }
}

void main()
{
    Foo foo;
    auto thread = new Thread(&foo.test);
    thread.start();
    thread.join();
    foo.test();
}

This prints the same addresses. std.concurrency won't let you do this,
while std.parallelism uses some form of "weaker isolation", and it
seems core.thread has the same weaker isolation principle.

If "foo" is in TLS, how come a new thread can access its members?


More information about the Digitalmars-d-learn mailing list