Boost logo

Boost Users :

Subject: Re: [Boost-users] Thread object pointers.
From: Nathan Crookston (nathan.crookston_at_[hidden])
Date: 2010-08-03 20:04:00

Hi Albert,

On Tue, Aug 3, 2010 at 3:10 PM, Albert Schueller <schuelaw_at_[hidden]> wrote:
> When I run LISTING 1 it appears that the threads are acting
> independently as I would hope.  When I run LISTING 2, it seems that the
> threads are not independent, but rather thrd1 does its job, followed by
> thrd2, followed by thrd3.
> Am I not locking properly?

Could it be that:
>  for(i=0;i<num_thrds;i++) {
>   thrd[i] = new boost::thread(count(i+1));
>   thrd[i]->join();
>  }

Should be:

for(i=0; i < num_thrds; i++)
  thrd[i] = new boost::thread(count(i+1));

for(i=0; i < num_thrds; i++)

Calling join prior to creating the next thread would cause the
sequential execution you were seeing.



Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at