Add and reduce windows core object semaphore

Source: Internet
Author: User

From: http://www.ibm.com/developerworks/cn/java/l-threadPool/

During software developmentProgramMutual communication is often required. For example, when several threads Add a message to the queue, while the other thread needs to wake up the thread to process things during sleep. In this case, the semaphore must be used for synchronization. Createsemaphore is the creation of semaphores, and releasesemaphore is the addition of semaphores. Semaphore is another synchronization problem mechanism. Whether it is event or mutex, when other processes hold waitforsingleobject, it depends on whether the current object is signal or unsignal and determines whether to wait, and semaphore is the same, but it will change to the signal/unsignal status, but it is somewhat different. It provides a Count value, which allows any thread that executes to waitforsingleobject within this Count value to not stop, andEach time waitforsingleobject is executed, the Count value is reduced by one.,When the Count value is 0, the semaphore is in the unsignal State, andWhen a thread releasesemaphore is created, the Count value is increased.So that other threads or signals of signal can be obtained, and waitforsingleobject stops waiting.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.