Thread congestion caused by usleep

Source: Internet
Author: User
Tags usleep

Thread congestion caused by usleep:

 

The thread is inexplicably congested. When we use GDB attach, we find that the thread is blocked in the usleep call. It seems that we have heard of such problems from other colleagues. Change usleep to select.

 

OS version:

[Umg @ zjdxc-slee1 umg] $ uname-
Linux zjdxc-slee1 2.6.18-53. el5pae #1 SMP wed Oct 10 16:48:18 EDT 2007 i686 i686 i386 GNU/Linux

 

 

Refer to http://hi.baidu.com/motadou/blog/item/afbe2a0f00cabaed36d122d0.html:

 

Usleep ()
Great Problems

    1. In some platforms, it is not thread-safe, such as HP-UX and Linux
    2. Usleep ()
      Will affect the signal
    3. In many platforms, such as HP-UX and some Linux, when the parameter value must be less than 1*1000*1000, that is, 1 second, otherwise the function reports an error and returns immediately.
    4. Most of the help documents on the platform have clearly stated that this function is a function that has been discarded.

Fortunately, there is a good function in the POSIX specification,Nanosleep ()
, This function does notUsleep ()
Its precision is in nanoseconds. In a Solaris multi-threaded environment, the compiler automaticallyUsleep ()
ConnectNanosleep ()
.

In Linux, the Select function is recommended for short latency.

 

 

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.