Boost logo

Boost Users :

Subject: [Boost-users] Boost Threads are not parallel
From: Panagiotis Foteinos (pafotein_at_[hidden])
Date: 2011-03-24 17:49:27


Hello users.

I observed the boost threads behave strangely, depending on the way I call
the function to be executed in parallel.

In the following example (example #1), the threads launched are executed in
parallel:
****************************************************************************************
1)
class Test
{

int insert(){};

} object;

boost::thread* threads = new boost::thread[N];
for(unsigned int i = 0; i < N; i++)
 {
     threads[i] = boost::thread(&Test::insert, &object);
 }
****************************************************************************************

However, in the following example (example #2), the threads are executed
sequentially. Only the line in the for-loop body differs from example#1.
****************************************************************************************
2)
class Test
{

int insert(){};

} object;

boost::thread* threads = new boost::thread[N];
int ret;
for(unsigned int i = 0; i < N; i++)
 {
     threads[i] = boost::thread(boost::lambda::var(ret) = object.insert());
 }

****************************************************************************************

Can anybody explain why the threads in example#2 are executed sequentially
(i.e., one at a time)?

Best Regards,
Panagiotis Foteinos



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