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.

Example of using CSemaphore - 1<br />

} CSemaphore, CMutex, and CCriticalSection all work in a<br />

similar manner.<br />

} Semaphore is a thread synchronization object that allows<br />

accessing the resource for a count between zero and<br />

maximum number of threads.<br />

} If the Thread enters the semaphore, the count is incremented.<br />

} If the thread completed the work and is removed from the<br />

thread queue, the count is decremented.<br />

} When the thread count goes to zero, the synchronization<br />

object is non-signaled. Otherwise, the thread is signaled.<br />

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