wxCriticalSectionLocker Class Reference | wxWidgets

| Version: 3.2.11

Loading...
Searching...
No Matches
Public Member Functions | List of all members
wxCriticalSectionLocker Class Reference
Class List by Category » Threading

`#include </cygdrive/c/Users/Hamis/Cygwin-packaging/wxWidgets3.2/wxWidgets3.2-3.2.11-1.x86_64/src/wxWidgets-3.2.11/interface/wx/thread.h>`

## Detailed Description

This is a small helper class to be used with wxCriticalSection objects.

A wxCriticalSectionLocker enters the critical section in the constructor and leaves it in the destructor making it much more difficult to forget to leave a critical section (which, in general, will lead to serious and difficult to debug problems).

Example of using it:

void Set Foo()
{
// gs_critSect is some (global) critical section guarding access to the
// object "foo"
wxCriticalSectionLocker locker(gs_critSect);
if ( ... )
{
// do something
...
return;
}
// do something else
...
return;
}
wxCriticalSectionLocker::wxCriticalSectionLocker
wxCriticalSectionLocker(wxCriticalSection &criticalsection)
Constructs a wxCriticalSectionLocker object associated with given criticalsection and enters it.

Without wxCriticalSectionLocker, you would need to remember to manually leave the critical section before each `return`.

##

Library: wxBase
Category: Threading

See also
  wxCriticalSection, wxMutexLocker

## Public Member Functions
| wxCriticalSectionLocker (wxCriticalSection &criticalsection)
| Constructs a wxCriticalSectionLocker object associated with given criticalsection and enters it.
| ~wxCriticalSectionLocker ()
| Destructor leaves the critical section.

## Constructor & Destructor Documentation

## ◆ wxCriticalSectionLocker()

wxCriticalSectionLocker::wxCriticalSectionLocker | ( | wxCriticalSection & | criticalsection | ) |

Constructs a wxCriticalSectionLocker object associated with given criticalsection and enters it.

## ◆ ~wxCriticalSectionLocker()

wxCriticalSectionLocker::~wxCriticalSectionLocker | ( |  | ) |

Destructor leaves the critical section.