Passing parameters to a thread
I've been using threading for a while, that was no needing parameters..
so I used for example the following line :
|
_beginthread(functionName, 0, (void*)10);
|
and it worked great...
but now I have a function that has an int parameter (int num), and I dont know how to transfer it using _beginthread...
I searched the net, but didnt found a solution for this...
Thanks!
I don't think this is standard C++. I guess I can only show you C++11 <thread> functionality.
http://en.cppreference.com/w/cpp/thread/thread
Otherwise, ask in the Windows programming subforum about this specific function (It is Windows, right?)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <thread>
#include <iostream>
void aux(int &a)
{
++a;
}
int main()
{
int a;
std::cin >> a;
std::thread thr(aux, std::ref(a));
thr.join();
std::cout << a;
return 0;
}
|
Topic archived. No new replies allowed.