Thread overview | |||||
---|---|---|---|---|---|
|
December 05, 2020 Is core.thread.osthread.Thread thread-safe? | ||||
---|---|---|---|---|
| ||||
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 Re: Is core.thread.osthread.Thread thread-safe? | ||||
---|---|---|---|---|
| ||||
Posted in reply to tsbockman | 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 Re: Is core.thread.osthread.Thread thread-safe? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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!
|
Copyright © 1999-2021 by the D Language Foundation