bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Use of Mutexes in Buffer is not exception save!


From: Frank Uepping
Subject: Use of Mutexes in Buffer is not exception save!
Date: Sat, 12 Jan 2002 17:30:39 +0100

Hi,
the functions Wait() and Post() are using EnterMutex() and LeaveMutex() to
acquire a lock (resource). Between them the virtual functions OnWait() and
OnPost() get called. If these virtual functions are throwing an exception the
Mutexes remain locked and may cause a deadlock, isn't it?
I suggest to use MutexLock instead.

int Buffer::Wait(void *buf)
{
        int     rc;

        size_head.Wait();
        lock_head.EnterMutex();
        rc = OnWait(buf);  //Mutex remains locked if an exception escapes!
        --_used;
        lock_head.LeaveMutex();
        size_tail.Post();
        return rc;      
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]