07.03.2013 Views

Multithreading Multi-Threaded Programming

Multithreading Multi-Threaded Programming

Multithreading Multi-Threaded Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Difference between<br />

CSingleLock ::Lock and CSyncObject::Lock<br />

} CCriticalSections are usually (not always) class members or<br />

global objects that never go out of scope. So if you use<br />

CCriticalSection::Lock() you have to remember to call<br />

CCriticalSection::Unlock().<br />

} This can be tricky to implement if your code can take many divergent<br />

paths inside the lock.<br />

} Using CSingleLock makes this much easier as you would<br />

normally declare the CSingleLock inside a function or loop or<br />

some other small bit of code where it goes out of scope and is<br />

destroyed when no longer needed. CSingleLock automatically<br />

unlocks the sync object from within its destructor, you do not<br />

have to explicitly call CSingleLock::Unlock().<br />

40<br />

Advanced Windows Network <strong>Programming</strong><br />

11/11/12

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!