On 12/12/06, Gabriel Ki <gabeki_corp@yahoo.com> wrote:
Hi,

I am just trying the boost threads example from the link.

#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/tss.hpp>
#include <iostream>

boost::mutex io_mutex;
boost::thread_specific_ptr<int> ptr;

struct count
{
count(int id) : id(id) { }

void operator()()
{
if (ptr.get() == 0)
ptr.reset(new int(0));

for (int i = 0; i < 10; ++i)
{
(*ptr)++;
boost::mutex::scoped_lock
lock(io_mutex);
std::cout << id << ": "
<< *ptr << std::endl;
}
}

int id;
};

int main(int argc, char*
argv[])
{
boost::thread thrd1(count(1));
boost::thread thrd2(count(2));
thrd1.join();
thrd2.join();
return 0;
}
There are two ways to work this, as far as I know:

[...]
count c1(1);
boost::thread thrd1( &c1 );
boost::thread thrd2( boost::bind( &count, 2 ) ); /* I think this works; it would if count was a function call */
[...]

It's not everything, but I HTH,
Darren