Passing parameters to thread functions
D_Starter via Digitalmars-d
digitalmars-d at puremagic.com
Sat Aug 15 05:22:07 PDT 2015
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.
More information about the Digitalmars-d
mailing list