Initializecriticalsectionandspincount ()

Source: Internet
Author: User

This API name is long enough. I like it! In fact, the critical_section operation is very lightweight. Why should I add the rotation lock? In fact, this function does not work on a single-CPU computer. It only works when there is more than one CPU on the computer, or a single CPU but multiple cores. If the operation that the critical section is used to protect takes a short time, for example, to protect a reference
Counter, or a flag, then several clock cycles will leave the critical section. However, before this thread leaves the critical section, another thread tries
This critical section -- this happens only on a multi-core or SMP system -- if the thread cannot be accessed, the thread goes to sleep, and then a context switch occurs. We know
Context
Switch is a time-consuming operation. It is said that it requires thousands of clock cycles. In fact, we only need to wait a few more clock cycles to enter the critical section, now there are thousands more clock cycle overhead.
Yes. Therefore, the initializecriticalsectionandspincount function is introduced. Its first parameter is the pointer to CS, and the second parameter.
Is the number of times of rotation. In my understanding, the number of loops, such as N, means that the entercriticalsection () function will cyclically determine whether the critical section can be entered.
Until it can be entered or N times full. The overhead we increase is a maximum of N cycles, and we may receive thousands of clock cycles as a bonus. For very short operations in the critical section, the advantage of doing so is great. On msdn, they used the n = 4000 rotation lock for the heap manager, and then "This gives great performance and scalability in almost all worst-case scenarios. "visible or useful :-) http://yjl.spaces.live.com/blog/cns! 8129c4219a8e995b! 466. Entry

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.