Boost logo

Boost Users :

From: Sohail Somani (sohail_at_[hidden])
Date: 2007-11-21 17:39:05


On Wed, 21 Nov 2007 23:25:36 +0100, Fabian Sturm wrote:

> This works fine and A will wait until the result is available and it
> doens't matter if it starts waiting before or after B finished
> calculaating.
> But the problem now is that B also needs to wait for A to reach the
> point in execution.

Why not do this:

void threadB()
{
  g_value = do_my_expensive_calc();
  barrier2.wait(); // start waiting *after* calculation is done
}

void threadA()
{
  barrier2.wait();
  // now can read value
  do_something_with_value(g_value)
}

Then thread B can calculate without waiting for thread A but neither
thread will exit until they both reach the barrier.

-- 
Sohail Somani
http://uint32t.blogspot.com

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