Oh I see. Something like this?
class MutexAbstraction
{
private:
MutexObject *itsMutex;
public:
MutexAbstraction(MutexObject *existingmutex) {itsMutex = existingmutex;
claim itsMutex};
~MutexAbstraction() {release itsMutex;};
}
SomeCode:
{
MutexAbstraction aMutex(a mutex created global scope);
protected code;
}
Perfectly legitimate and almost fool proof. If that kind of code crashes, it could only be if your stack gets overtrampled (more precisely, the itsMutex element of the dummy class instance on your application stack would), but I would expect it to crash in a different position then.
Usual question: Are all your app stacks big enough?