PDA

View Full Version : Suggest hiding mutex::lock and unlock



MikiJ
09-29-2008, 02:33 PM
Hi,

I suggest making mutex lock and unlock private rather then public as they are now.

The only reason is avoid potential nasty cases where in:

mutex.lock();
do_something();
mutex.unlock();

do_something throws exception. This will leave mutex locked, and then heavens help you debugging these cases...

One can do the same thing using MutexSection:

CL_MutexSection section( mutex );
do_something_with_lock();
section.unlock();
do_something_without_lock();

but in this case any exceptions will release the lock properly.

I am sure Mutex and Section were meant to be used this way. But hiding Mutex modifiers will simply enforce this good design without any drawbacks that I can see.

While we're at it, changing documentation to show only the good usage would be advisable. I will gladly do it, but I am getting my feet wet only, have not generated docs once yet...

Miki.

rombust
10-01-2008, 02:28 PM
[snip]
However, I could be totally wrong!
...
i was totally wrong!