Click here to Skip to main content
16,004,778 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to draw static controls and check box buttons transparently ? Pin
rrrado5-Jan-05 3:41
rrrado5-Jan-05 3:41 
GeneralRe: How to draw static controls and check box buttons transparently ? Pin
YoSilver7-Jan-05 0:35
YoSilver7-Jan-05 0:35 
GeneralRe: How to draw static controls and check box buttons transparently ? Pin
rrrado11-Jan-05 4:04
rrrado11-Jan-05 4:04 
GeneralRe: How to draw static controls and check box buttons transparently ? Pin
YoSilver11-Jan-05 6:35
YoSilver11-Jan-05 6:35 
GeneralAccessing Large CMapStringToString's inside Critical Sections Pin
MJWhiteman25-Jan-05 2:56
MJWhiteman25-Jan-05 2:56 
GeneralRe: Accessing Large CMapStringToString's inside Critical Sections Pin
basementman5-Jan-05 4:38
basementman5-Jan-05 4:38 
GeneralCritical Sections Pin
MJWhiteman25-Jan-05 2:47
MJWhiteman25-Jan-05 2:47 
GeneralRe: Critical Sections Pin
Martin Koorts5-Jan-05 3:25
Martin Koorts5-Jan-05 3:25 
Hi Matt

The CCriticalSection class is the lock that is accessed from more than 1 thread and ensures that if 1 thread has called CCriticalSection::Lock (not having called CCriticalSection::Unlock yet), another thread's call to CCriticalSection::Lock will block - effectively suspending the second thread until the first calls CCriticalSection::Unlock.

The CSingleLock class is simply a smart-pointer style helper class that acts on the CSyncObject that is passed in with it's constructor - in essence, it just calls the CSyncObject::Lock in it's constructor and CSyncObject::Unlock in the destructor. That way you can have the SyncObject's Unlock method automatically called when the CSingleLock local variable goes out-of-scope....
but an example says a thousand words;



CCriticalSection csGlobal; // global variable, or such..

void Thread1()
{
CSingleLock lock(&csGlobal);
// do stuff
}

void Thread2()
{
CSingleLock lock(&csGlobal);
// do stuff
}

So you can see that the smart-pointer style local CSingleLock instances really just capitalise on the C++ destructor to help you remember to call csGlobal.Unlock. Without the CSingleLock, you could end up writing (faulty) code like this;

void Thread3()
{
csGlobal.Lock();
// do some stuff
if (bFailed)
return; // !!!! didn't call csGlobal.Unlock();
// do more stuff
csGlobal.Unlock();
}

Lastly, the explicit Lock/Unlock methods on CSingleLock is really if you can't wait for the destructor, and need to Unlock and possibly Lock again.

I hope this makes sense.
Martin
GeneralC++ code size Pin
Defenestration5-Jan-05 2:19
Defenestration5-Jan-05 2:19 
GeneralRe: C++ code size Pin
David Crow5-Jan-05 5:22
David Crow5-Jan-05 5:22 
GeneralRe: C++ code size Pin
Defenestration5-Jan-05 7:11
Defenestration5-Jan-05 7:11 
GeneralRe: C++ code size Pin
David Crow5-Jan-05 7:52
David Crow5-Jan-05 7:52 
GeneralRe: C++ code size Pin
Gerald Schwab5-Jan-05 11:25
Gerald Schwab5-Jan-05 11:25 
Generaltopics for project Pin
V.G5-Jan-05 2:17
V.G5-Jan-05 2:17 
GeneralRe: topics for project Pin
Maximilien5-Jan-05 2:26
Maximilien5-Jan-05 2:26 
GeneralRe: topics for project Pin
V.G22-Jan-05 2:28
V.G22-Jan-05 2:28 
GeneralRe: topics for project Pin
David Crow22-Jan-05 13:03
David Crow22-Jan-05 13:03 
GeneralRe: topics for project Pin
Anonymous24-Jan-05 2:46
Anonymous24-Jan-05 2:46 
GeneralRe: topics for project Pin
David Crow24-Jan-05 3:07
David Crow24-Jan-05 3:07 
GeneralRe: topics for project Pin
act_x5-Jan-05 3:44
act_x5-Jan-05 3:44 
GeneralRe: topics for project Pin
David Crow5-Jan-05 5:35
David Crow5-Jan-05 5:35 
GeneralChecking if a file has been opened by any process and remains open Pin
Jose M Castellanos5-Jan-05 0:33
Jose M Castellanos5-Jan-05 0:33 
GeneralRe: Checking if a file has been opened by any process and remains open Pin
Rajesh match5-Jan-05 0:47
Rajesh match5-Jan-05 0:47 
GeneralRe: Checking if a file has been opened by any process and remains open Pin
cmk5-Jan-05 9:38
cmk5-Jan-05 9:38 
GeneralActive X Kids!! Pin
rw1044-Jan-05 23:06
rw1044-Jan-05 23:06 

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.