Click to See Complete Forum and Search --> : Critical Section


cabasm
October 11th, 2004, 08:26 AM
Does anybody know a .NET class wrapper for critical sections? (InitializeCriticalSection, EnterCriticalSection, LeaveCriticalSection and DeleteCriticalSection)

darwen
October 14th, 2004, 05:15 AM
There are locking capabilities in C# with the 'lock' keyword but I've never been able to find any in C++.NET.

Another way of doing critical sections is to use an AutoResetEvent :


public __gc class Synchronised
{
public:
Synchronised()
{
m_pEvent = new System::Threading::AutoResetEvent(true);
}

void SynchronisedFunction()
{
m_pEvent->WaitOne();

// this is now in a critical section

m_pEvent->Set();
}
} ;


Get the idea ?

Darwen.

cabasm
October 14th, 2004, 08:10 AM
Is there a mutex or an event object instead?

darwen
October 14th, 2004, 01:14 PM
Mutexes are slow if you're not doing inter-process (i.e. not interthread) critical sections.

The above was an event.

Actually, i'm pretty sure there's locking classes in System::Threading as well - have a look in MSDN.

Darwen.