Contents Up Previous Next

wxCriticalSection

A critical section object is used for exactly the same purpose as mutexes. The only difference is that under Windows platform critical sections are only visible inside one process, while mutexes may be shared between processes, so using critical sections is slightly more efficient. The terminology is also slightly different: mutex may be locked (or acquired) and unlocked (or released) while critical section is entered and left by the program.

Finally, you should try to use wxCriticalSectionLocker class whenever possible instead of directly using wxCriticalSection for the same reasons wxMutexLocker is preferrable to wxMutex - please see wxMutex for an example.

Derived from

None.

Include files

<wx/thread.h>

See also

wxThread, wxCondition, wxCriticalSectionLocker

Members

wxCriticalSection::wxCriticalSection
wxCriticalSection::~wxCriticalSection
wxCriticalSection::Enter
wxCriticalSection::Leave


wxCriticalSection::wxCriticalSection

wxCriticalSection()

Default constructor initializes critical section object.


wxCriticalSection::~wxCriticalSection

~wxCriticalSection()

Destructor frees the resources.


wxCriticalSection::Enter

void Enter()

Enter the critical section (same as locking a mutex). There is no error return for this function. After entering the critical section protecting some global data the thread running in critical section may safely use/modify it.


wxCriticalSection::Leave

void Leave()

Leave the critical section allowing other threads use the global data protected by it. There is no error return for this function.