Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost threads with arguments
From: Robert Abel (abel_at_[hidden])
Date: 2012-06-04 03:12:43


Hi,

On 03.06.2012 22:11, Jamie Lahowetz wrote:
> I am trying to pass two arguments to a boost thread using this call:
> boost::thread workerthread(&SshClient::SSHconnect,&sshclt,1,provec);
>
> the method for SSHconnect is:
> int SSHconnect(int,vector<string>);
>
You will have to use boost::bind to bind the instance and additional
arguments to your thread.
See for example http://blog.emptycrate.com/node/277.

Seemingly, what you originally wanted to use was the thread constructor
with arguments
<http://www.boost.org/doc/libs/1_49_0/doc/html/thread/thread_management.html#thread.thread_management.thread.multiple_argument_constructor>.
However, notice that it actually will create a copy of your object,
which is not what you want.
You will want to use bind with pointer to members
<http://www.boost.org/doc/libs/1_49_0/libs/bind/bind.html#with_member_pointers>.
So _this_ will refer to your object inside the newly created thread.

Regards,

Robert



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net