Click here to Skip to main content
15,919,479 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: EnterCriticalSection() exception issue Pin
Tnarol5-Oct-06 4:54
Tnarol5-Oct-06 4:54 
GeneralRe: EnterCriticalSection() exception issue Pin
led mike5-Oct-06 5:06
led mike5-Oct-06 5:06 
GeneralRe: EnterCriticalSection() exception issue Pin
Tnarol5-Oct-06 5:36
Tnarol5-Oct-06 5:36 
GeneralRe: EnterCriticalSection() exception issue Pin
led mike5-Oct-06 6:13
led mike5-Oct-06 6:13 
AnswerRe: EnterCriticalSection() exception issue Pin
Mark Salsbery5-Oct-06 7:35
Mark Salsbery5-Oct-06 7:35 
GeneralRe: EnterCriticalSection() exception issue Pin
Tnarol5-Oct-06 22:07
Tnarol5-Oct-06 22:07 
GeneralRe: EnterCriticalSection() exception issue Pin
Mark Salsbery6-Oct-06 5:08
Mark Salsbery6-Oct-06 5:08 
AnswerRe: EnterCriticalSection() exception issue Pin
Blake Miller6-Oct-06 8:50
Blake Miller6-Oct-06 8:50 
You need two SEPARATE objects.

The first object constructor initializes the critical section, and its destructor deletes the critical section.
It has a member function Lock() and Unlock()

The second class, its constructor Enters the critical section of first object, by calling its Lock function. The destructor of this class calls the Unlock() of the first class.

That way, you don't have to worry about calling Unlock() explicitly from your code.
You also don't have to use a 'global' class from your common code, you use instances of the second class.

If you don't want to block out the entire scope of a function, then use the local scoping operators around the second class and the code like so

{
SecondClass MyLocker;
... code
}

and it will release when closing brace is met.

This is also handy when there is an exception, your critical section is not permanently locked and lost by the unwinding of the exception.



Any sufficiently gross incompetence is nearly indistinguishable from malice.

QuestionAbsolute Addresses Pin
Big CDF5-Oct-06 3:39
Big CDF5-Oct-06 3:39 
AnswerRe: Absolute Addresses Pin
David Crow5-Oct-06 3:47
David Crow5-Oct-06 3:47 
GeneralRe: Absolute Addresses Pin
Big CDF5-Oct-06 11:58
Big CDF5-Oct-06 11:58 
GeneralRe: Absolute Addresses Pin
Jörgen Sigvardsson5-Oct-06 13:54
Jörgen Sigvardsson5-Oct-06 13:54 
AnswerRe: Absolute Addresses Pin
kakan5-Oct-06 19:49
professionalkakan5-Oct-06 19:49 
QuestionDoDataExchange Pin
Sonia Horra5-Oct-06 3:38
Sonia Horra5-Oct-06 3:38 
AnswerRe: DoDataExchange Pin
David Crow5-Oct-06 3:48
David Crow5-Oct-06 3:48 
GeneralRe: DoDataExchange Pin
Sonia Horra5-Oct-06 19:19
Sonia Horra5-Oct-06 19:19 
GeneralRe: DoDataExchange Pin
David Crow6-Oct-06 2:27
David Crow6-Oct-06 2:27 
GeneralRe: DoDataExchange Pin
Blake Miller6-Oct-06 8:52
Blake Miller6-Oct-06 8:52 
QuestionCDocument & CMainFrame. Pin
mostafa_pasha5-Oct-06 3:34
mostafa_pasha5-Oct-06 3:34 
QuestionRe: CDocument & CMainFrame. Pin
David Crow5-Oct-06 3:50
David Crow5-Oct-06 3:50 
AnswerRe: CDocument & CMainFrame. Pin
mostafa_pasha5-Oct-06 5:45
mostafa_pasha5-Oct-06 5:45 
GeneralRe: CDocument & CMainFrame. Pin
David Crow5-Oct-06 6:00
David Crow5-Oct-06 6:00 
GeneralRe: CDocument & CMainFrame. Pin
mostafa_pasha5-Oct-06 6:20
mostafa_pasha5-Oct-06 6:20 
GeneralRe: CDocument & CMainFrame. Pin
David Crow5-Oct-06 6:58
David Crow5-Oct-06 6:58 
GeneralRe: CDocument & CMainFrame. Pin
mostafa_pasha5-Oct-06 7:15
mostafa_pasha5-Oct-06 7:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.