Možda si mislio na
RAII (a to je u suštini ono što je rekao NastyBoy u vezi STL-a) ?
("The RAII technique is often used for controlling thread locks in multi-threaded applications.")
Imaš primer za "file".
Ili, nešto slično:
--- H ---
Code:
class NEKA_KLASA
{
// ...
CRITICAL_SECTION LogCriticalSection;
// ...
};
--- H ---
Code:
class CSLock
{
public:
LPCRITICAL_SECTION fcs;
CSLock( LPCRITICAL_SECTION acs ) : fcs( acs )
{ if ( fcs ) EnterCriticalSection( fcs ); }
~CSLock()
{ if ( fcs ) LeaveCriticalSection( fcs ); }
};
--- CPP ---
Code:
void NEKA_KLASA::GoSendMessageToLog( string AEvent )
{
CSLock lock( &LogCriticalSection );
// ...
// ... ovde je thread safe kod
// ...
}
NEKA_KLASA::NEKA_KLASA() // konstruktor
{
// ...
InitializeCriticalSection( &LogCriticalSection );
// ...
}
NEKA_KLASA::~NEKA_KLASA() // destruktor
{
// ...
DeleteCriticalSection( &LogCriticalSection );
// ...
}
[Ovu poruku je menjao X Files dana 29.04.2008. u 08:08 GMT+1]