incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <>
Subject [Incubator Wiki] Update of "CppTips/PrivateLocking" by AlanConway
Date Fri, 08 Sep 2006 19:54:11 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Incubator Wiki" for change notification.

The following page has been changed by AlanConway:

New page:
The only way to write thread safe code without losing your mind is to keep your synchronisation
simple and small. You cannot test for thread safety. Really you can't. If synchronization
is complicated or spread out it's pretty much impossible to know by inspection whether it's

A key technique is to encapsulate synchronization ''inside'' thread-safe classes. Every public
member function should protect ''itself'' from concurrent access by using private locks or
other synchronization objects. You can verify the synchronization of just that class in isolation.
It's much easier to build complicated thread-safe code from simple pieces that you know to
be individually thread-safe.

It's very dangerous to provide public access to locks because now to establish thread safety
for a class you have to inspect ''every potential use'' of that class. Not to mention every
change to or addition of code using the class. Did I mention losing your mind?

CppTips/ThreadSafety provides a bit more on the subject.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message