Boost logo

Boost :

From: Dietmar Kuehl (dietmar_kuehl_at_[hidden])
Date: 2000-08-08 16:28:46


Hi,
--- Milutin Jovanovic <miki_at_[hidden]> wrote:
> First there are legitimate uses of long locks, so you should not try
> to stop such usage.

I keep asking for multi threading related idioms but nobody has
proposed something using long locks. Thus, I'm assuming that they don't
have any use. This matches the implied threading interface of Java,
where only functions are synchronized.

However, if there are indeed usage patterns which use long locks, it
would be rather useful to learn about them. Still, my impression is
that this would not use public "lock()" methods on the mutex. There
are other approaches which I consider preferable over using 'catch'
clauses which I consider extremely error prone.

> Finally, what stops the user from dynamically allocating the
> 'auto_lock' object?

A private 'operator new()', for example. ... or the lock is returned
from the 'lock()' method and passed around as long as the lock is to
be retained. This also addresses the long lock issue. Of course, the
lock can be embedded in a class created for this specific purpose.
However, the philosophy of C++ is to work against Murphy, not against
Machiavelli.

> This is not to say that locks should be used indiscriminately. Proper
> thread synchronisation takes extreme discipline. My view is however
> that education is the only way to achieve this.

My view is that it can be made harder to make dump errors: Education
does not help against dump errors and against me being forgetful. ...
and if there is no 'lock()' method in the mutex, people will have to
look at the documentation to find out how to lock it, fostering
education. If there is a 'lock()' method, guess what is used despite
the documentation is saying it is a dangerous thing to do! My
experience is, that the average programmer never reads documentation
and, even worse, is proud of this. This view is at least partially
supported by a current thread in comp.lang.c++.moderated.

=====
<mailto:dietmar_kuehl_at_[hidden]>
<http://www.dietmar-kuehl.de/>

__________________________________________________
Do You Yahoo!?
Kick off your party with Yahoo! Invites.
http://invites.yahoo.com/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk