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
- In some platforms, it is not thread-safe, such as HP-UX and Linux
- Usleep ()
Will affect the signal
- 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.
- 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.