Thread Attributes

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 10 23:38:40 PDT 2014


On 10/07/14 20:12, Jonathan Marler wrote:
> I had an idea this morning and wanted to post it to see what people think.
>
> I know we have alot of attributes already but I'm wondering if people
> think adding a thread attribute could be useful. Something that says a
> variable or function or class/struct can only be accessed by code that
> has been tagged with the same thread name.  Something like this.
>
> // This variable is allocated as a true shared global
> // with a fixed location in memory since it can only
> // be accessed by one thread.
> @thread:main
> int mainThreadGlobal;
>
> @thread:main
> int main(string[] args)
> {
>    // Start the worker thread at some point
> }
>
> @thread:worker
> void workerLoop()
> {
>    // do some work , cannot access mainThreadGlobal
> }

I'm not sure I understand but if the variable can only be accessed from 
a single thread, why not make it thread local?

> [SNIP]
> So what do people think?  Like I said I just thought of this and haven't
> had time think about more corner cases so feel free to nit pick:)

BTW, both of these features sounds like a job for AST macros.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list