Boost logo

Boost Users :

From: Ben Hutchings (ben.hutchings_at_[hidden])
Date: 2005-04-22 11:51:58


Sliwa, Przemyslaw (London) wrote:
> Volodya,
>
> Thanks for answer.
> Right I have forgotten to put the subject->it was stupid.
> But the try_mutex and scoped_tyy_lock cause that both processors are
> used properly.
>
> Can you explain?
<snip>

You don't seem to understand what mutexes are. They do not magically
make regions of code thread-safe. They provide _mut_ual _ex_clusion;
that is, they allow only one thread at a time to acquire them. Since
virtually all the work of the program depends on acquisition of a single
mutex, only one thread can run for most of the time, and only one
processor will be used.

The try_mutex/scoped_try_lock combination allows you to attempt to
acquire the mutex without blocking; obviously this can fail. If you
don't test for failure, you might as well not use the mutex at all.

In your example of calculating square roots there is no shared data and
no need for the mutexes. In a real multithreaded program the challenge
is to organise shared data and mutexes so that threads rarely contend
for the same mutex.

Ben.


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