boost thread function arguments passed as reference (boost::ref() seems not to work...)

88 Views Asked by At

I have the following simple function:

void hda(unsigned long &command)
{
    command++;
    PlugIn::gResultOut << "inside thread: " << command << std::endl;

return;
}

and I am creating a boost::thread as

void SU_HThread(unsigned long &command)
{
    command++,
    PlugIn::gResultOut << "before thread: " << command << std::endl;

    boost::thread Hthread = boost::thread(boost::bind(boost::move(hda), boost::ref(command)));

return;
}

But when I call this function, the command value, which is updated inside the thread is not registered...

number com = 0

SU_HThread(com) 
sleep(1) // sleep 1 second
result("after thread: "+com+" \n")

Output:

before thread: 1
inside thread: 2
after thread: 1 

The usual answer with boost::ref(command) does not seem to work here.... Any ideas? Preferably without using promises, since I need to observe the change in command value in realtime.

thanks!

0

There are 0 best solutions below