Boost logo

Boost Users :

From: Sliwa, Przemyslaw (London) (Przemyslaw_Sliwa_at_[hidden])
Date: 2005-04-22 06:25:16


All,
 
I have found a very strange behaviour (for me at least!) in
boost.Thread.
The same dummy code:
boost::mutex M;

void functionA(int j)

{

for(int i=0; i<j; ++i)

{

 boost::mutex::scoped_lock lock(M);

sqrt(static_cast<double>(i));

}

}

void functionB(int j)

{

for(int i=0; i<j; ++i)

{

 boost::mutex::scoped_lock lock(M);

sqrt(static_cast<double>(i));

}

}

int main()

{

thread A(bind(&functionA, 1000000000)), AA(bind(&functionA,
1000000000)),

B(bind(&functionB, 100000000)), BB(bind(&functionA, 100000000));

A.join();

B.join();

AA.join();

BB.join();

}

 
executed on a two processor machine uses the resourced differently
depending if the line
 boost::mutex::scoped_lock lock(M);

is comennted or not.

If we do not lock the mutex then both processors are used on 100%.
However, in case the line is uncommented (we lock the mutex) only one
processor is used. Can anyone explain me why?

 

Thanks in advance

 

Pshemek
--------------------------------------------------------

If you are not an intended recipient of this e-mail, please notify the sender, delete it and do not read, act upon, print, disclose, copy, retain or redistribute it. Click here for important additional terms relating to this e-mail. http://www.ml.com/email_terms/
--------------------------------------------------------



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