Thread Attributes
Jonathan Marler via Digitalmars-d
digitalmars-d at puremagic.com
Sat Jul 12 08:38:44 PDT 2014
On Friday, 11 July 2014 at 18:56:07 UTC, Timon Gehr wrote:
> On 07/10/2014 08:12 PM, Jonathan Marler wrote:
>> So what do people think?
>
> How do you make sure there is at most one thread of each kind?
Good question. First, since the language doesn't support starting
threads itself (like Go) but instead uses a library, the compiler
would likely need to be modified to semantically understand
whenever a line of code is starting a thread (I'm assuming it
doesn't already). If this feature were interesting enough I'm
sure Walter would have an opinion on the right way to accomplish
this.
Then how do you make sure that every named thread is only started
once? The ideal situation would be to verify this at compile
time. This is possible in some situations. If it is not
possible to verify this at compile time then the compiler could
generate a synchronized global pointer to every named thread to
prevent each one from getting started more than once. However,
one thought that comes to mind is if the developer cannot change
the code to be able to verify that the thread is only started
once at compile-time then maybe their code is poorly designed or
they are using this feature incorrectly.
This is just a random thought I had after writing this but maybe
if you could somehow tell the compiler that a section of code
will only ever be executed once it would help in this analysis.
@executeonce. The main function would obviously only be executed
once, so any function that executes once would need to be called
at most once and you can directly trace where it is called from
the main thread. However I'm not sure how useful this feature
would be in the general case...I would have to think on it more.
More information about the Digitalmars-d
mailing list