Thread overview
Is core.thread.osthread.Thread thread-safe?
Dec 05, 2020
tsbockman
Dec 05, 2020
Adam D. Ruppe
Dec 05, 2020
tsbockman
December 05, 2020
I want to do this:

import core.thread.osthread : Thread;

void main() {
    shared(Thread) thread1 = new Thread({
        // Do stuff for a while...
    });

    auto thread2 = new Thread({
       // ...
       if(thread1.isRunning)
           // Do a thing.
       else
           // Do a different thing.
       // ...
   });

    auto thread3 = new Thread({
       // ...
       if(thread1.isRunning)
           // Do a thing.
       else
           // Do a different thing.
       // ...
   });
}

However, I get various compile-time errors when I try to write code like this because nothing in the Thread API is annotated `shared`. Are Thread objects really not thread-safe, and if so what is the correct way to synchronize access to one?

(The documentation for core.thread is broken right now, with dead links and at least one reference to an example that doesn't actually appear anywhere on the page.)
December 05, 2020
On Saturday, 5 December 2020 at 18:48:19 UTC, tsbockman wrote:
> (The documentation for core.thread is broken right now, with dead links and at least one reference to an example that doesn't actually appear anywhere on the page.)

im not sure about your other question but use my docs they actually work (...for the most part lol)

http://dpldocs.info/core.thread


I don't personally use the shared modifier here, you can just access stuff without it like in the source it does thigns like atomicLoad so like i think it is ok but idk eally.
December 05, 2020
On Saturday, 5 December 2020 at 18:58:13 UTC, Adam D. Ruppe wrote:
> On Saturday, 5 December 2020 at 18:48:19 UTC, tsbockman wrote:
>> (The documentation for core.thread is broken right now, with dead links and at least one reference to an example that doesn't actually appear anywhere on the page.)
>
> im not sure about your other question but use my docs they actually work (...for the most part lol)
>
> http://dpldocs.info/core.thread

Yes, yours are much better - they have a bunch of content which is mysteriously missing from the official docs build. Thanks!