07.03.2013 Views

Multithreading Multi-Threaded Programming

Multithreading Multi-Threaded Programming

Multithreading Multi-Threaded Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

How to determine which is suitable?<br />

} To determine which synchronization class you should use, ask<br />

the following series of questions:<br />

} Does the application have to wait for something to happen before it can<br />

access the resource (for example, data must be received from a<br />

communications port before it can be written to a file)?<br />

} If yes, use CEvent.<br />

} Can more than one thread within the same application access this<br />

resource at one time (for example, your application allows up to five<br />

windows with views on the same document)?<br />

} If yes, use CSemaphore.<br />

} Can more than one application use this resource (for example, the<br />

resource is in a DLL)?<br />

} If yes, use CMutex. Mutex object allows synchronizing objects across the process.<br />

} If no, use CCriticalSection. The critical section object synchronizes threads<br />

within the process. Critical section allows accessing only one thread at a time.<br />

41<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!