Passing parameters to thread functions

anonymous via Digitalmars-d digitalmars-d at puremagic.com
Sat Aug 15 05:49:45 PDT 2015


On Saturday, 15 August 2015 at 12:22:08 UTC, D_Starter wrote:
> int main()
> {
>     uint var = 7;
>     auto thread1 = new Thread(&thread_proc, val).start();  /* 
> similar to C++ STL */
>     thread1.join();
>
>     return 0;
> }
> [/CODE]
>
> You might have guessed...this won't work. So how do I pass 
> parameters to thread functions? I haven't found anything useful 
> on the library description so far.

You can pass a delegate that calls the function:
----
uint val = 7;
auto thread1 = new Thread({thread_proc(val);}).start();
----

If you have more questions, please post them to the 'learn' group 
(<http://forum.dlang.org/group/learn>) and not here.


More information about the Digitalmars-d mailing list