Thanks for your reply. Perhaps I didn't made myself clear enough. I
was looking for a template like the following (it uses MS's MFC
classes, so its not platform-independent, but you should get the
idea):
template<class t_Type>
class ProtectedVariable
{
public:
t_Type& operator= (const t_Type& Other)
{
// Lock the mutex first.
CSingleLock ProtectionMutexLock (&m_ProtectionMutex, TRUE);
m_Variable = Other;
return m_Variable;
}
t_Type get ()
{
// Lock the mutex first.
CSingleLock ProtectionMutexLock (&m_ProtectionMutex, TRUE);
return m_Variable;
}
protected:
t_Type m_Variable;
CMutex m_ProtectionMutex;
};
This template can then be used like this:
class SomeClass
{
public:
ProtectedVariable<double> DoubleVariable;
};
Actually, above class pretty much covers all I want, but
(A) it is not platform-independent and
(B) not part of any standard library.
Thanks,
Stuart