Passing parameters to thread functions
D_Starter via Digitalmars-d
digitalmars-d at puremagic.com
Sat Aug 15 05:24:55 PDT 2015
On Saturday, 15 August 2015 at 12:22:08 UTC, D_Starter wrote:
> Hey there,
>
> I'm in the process of learning D, switching from C/C++ and
> Pascal. In this I've come across multithreading capabilities.
>
> What I'm trying to achieve is to create a thread, call a thread
> function with parameters and have the thread return something.
> Like this:
>
> [CODE]
> import core.thread;
>
> void thread_proc(ref uint var)
> {
> uint v = var << 1;
> var = v;
> }
>
> 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.
>
> I've already learned that using shared global variables does
> work, but that's not what I want.
In main() it's meant to be uint val = 7;
More information about the Digitalmars-d
mailing list