The pre-write code encounters a situation where usleep will die under multiple threads.Look at the log is the thread stuck, so gdb went in to see, but did not find the deadlock, or normal stay in the usleep, and finally found that it is usleep in
1:sleep ()The minimum unit of seconds.When using Sleep/ulseep/select, because the thread will go to sleep state, and then wake up, if the single execution problem is not small, if the number of cycles executed more, then the difference is very large.
The use and difference of sleep () and Usleep () for Linux
[Date: 2013-03-23]
Source: Linux Community Fireroll
[Font: Big Small]
Function Name: SleepHeader file: #include //use with top file in VC#include //The
1. usleep is inaccurate on different hardware platforms, for example, usleep (2*1000). The result is sleep for 10 ms. Is it too much? The test code is as follows:
#include #include int main(int argc,char **argv){ struct timeval oldTime, newTime;
[RK_2014_0918] in linux, test the impact of usleep function on CPU usage. rk_2014_0918usleep
1. Local Environment
CPU information Intel (R) Core (TM) i3 cpu m 350 @ 2.27 GHz
Intel(R) Core(TM) i3 CPU M 350 @ 2.27GHz
Intel(R) Core(TM) i3 CPU M 350
Function name: sleepHeader file: #include //use with top file in VC#include //The header file used in the GCC compiler differs depending on the GCC versionFunction: Execution suspend specified number of secondsSyntax: unsigned sleep (unsigned
Function Name: Sleep
Header file: #include //use with top files in VC
#include //In the GCC compiler, the header file used differs depending on the version of GCC
Function: Execution suspend specified number of seconds
Grammar: Unsigned sleep
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
Function Name: Sleep
Header file: #include //use with top files in VC
#include //In the GCC compiler, the header file used differs depending on the version of GCC
Function: Execution suspend specified number of seconds
Grammar: Unsigned sleep
ArticleDirectory
Latency using I/O Ports
Latency using a combination of languages
Linux accurate time sequence (sleep, usleep, nanosleep)
11:36:48| Category:Linux| Tag:None |Font Size Subscription
First of all, I
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.