On Sunday, 10 September 2017 at 21:38:03 UTC, Cecil Ward wrote:
On Wednesday, 6 September 2017 at 15:55:35 UTC, Ali Çehreli wrote:
[...]

Ali, I have worked on operating systems' development in r+d. My definitions of terms are hopefully the same as yours. If we refer to two threads, if they both belong to the same process, then they share a common address space, by my definition of the terms 'thread' and 'process'. I use thread to mean basically a stack, plus register set, a cpu execution context, but has nothing to do with virtual memory spaces or o/s ownership of resources, the one exception being a tls space, which by definition is one-per-thread. A process is one or more threads plus an address space and a set of all the resources owned by the process according to the o/s. I'm just saying this so you know how I'm used to approving this.

[...]




I wrote this program :-

import std.stdio;
import std.concurrency;

int data;

void display()
{
    writeln("Address is ", &data);
}

void main()
{
    auto tid1 = spawn(&display);
    auto tid2 = spawn(&display);
    auto tid3 = spawn(&display);
}

It displayed :-

Address is 51AD20
Address is 51AD20
Address is 51F6D0
Address is 521AC0

This indicated to me that a thread local variable does in fact have a different address to other thread's instances of the same thread so you can in fact pass the address to another thread and access it from there via pointer, which is what I'd hope.

Interesting it also (sometimes) prints one of the lines twice quite often. I wonder if this is the same "bug" as https://issues.dlang.org/show_bug.cgi?id=17797 that doesnt even require any reading? (platform is windows 7 DMD32 D Compiler v2.076.0)

Reply via email to