Questions tagged [usleep]

usleep is a function provided by various languages and run times that delays a script or program by an amount of time specified in micro-seconds (µ - micro).

Details of how to use usleep vary by implementation.

94 questions
2
votes
1 answer

how to make an application resilient to clock_settime

An application (running on linux 2.6.31) is paced using usleep calls. However, it looks like it is not resilient to a date change (either using date from a shell or using clock_settime from another process). What is the right thing to do to avoid…
Laurent G
  • 2,994
  • 1
  • 18
  • 10
2
votes
1 answer

An animated processing icon, pure C

I want to make an animated processing icon outputted in console via C. #include #include #include #include void render_processing_icon(int turnovers_qt) { char *icon_characters = "|/-\\\0"; for (int i =…
user10438535
2
votes
1 answer

Delaying Code Execution on OSX 10.10

I've encountered a very strange issue that affects my code running only on OSX 10.10 systems. I've seen this anomaly occur on over 25 OSX 10.10 systems running my code, whereas the exact same code did not exhibit this behavior before upgrading…
Authman Apatira
  • 3,994
  • 1
  • 26
  • 33
2
votes
1 answer

Random print program, prints multiple outputs at once despite sleep() function?

So, I have the program below. What it does is, it prints random numbers while formating them with a width of 10 on the console. Now, when I added the sleep function, I expected it to print one number every 10 milliseconds (or more), but what it does…
ShadoWalkeR
  • 123
  • 1
  • 8
2
votes
5 answers

Relinquish Processor Time in C++ (Windows)

I've looked around a fair amount and can't seem to find what I'm looking for, but let me first stress that I'm not looking for a high-precision sleep function. Here's the background for the problem I'm trying to solve: I've made a memory mapping…
jknielse
  • 701
  • 1
  • 6
  • 10
2
votes
2 answers

usleep() to calculate elapsed time behaves weird

I am calculating time elapsed in milli seconds for each successive call to handler function using the code below. When i use usleep(1000) i.e. 1 ms time difference between each call is 10 ms and when i use usleep(1000000) i.e. 1 sec surprisingly…
vikas_2kx
  • 37
  • 6
1
vote
1 answer

Command "strace -T" introducing too much overhead

I'm trying to check the execution time of each system call invoked by my application using strace -T. I got the trace output. But the time calculated by strace for each system call seemed inaccurate. To confirm the accuracy, I added few usleep(100)…
1
vote
0 answers

How to implement high precision sleep by using Python?

I'm currently doing a research which I need to implement high precision sleep function, within 10-100 (us) microsecond accuracy, is there has any possible method I can achieve that? I tried to use time.sleep(50/1000000), but it not working. This…
leo0807
  • 941
  • 1
  • 8
  • 21
1
vote
1 answer

How to slow down only the current request? sleep() doesn't work as expected

Sometimes my application needs to wait for something. For example, in case of caching: if an object is not found in the cache, then the script sets a special value under its key, symbolizing the fact that its value is currently being calculated, and…
user10021762
1
vote
1 answer

why time spent on same function/method call differs much with or without sleep/usleep in the while loop?

my original c++ demo code is shown as follows: int counter = 0; while (counter < 5) { auto start = std::chrono::high_resolution_clock::now(); // instance and result are pre-defined local variables instance.Search(40.055948, 116.411325,…
Peng Wang
  • 11
  • 3
1
vote
2 answers

Interrupt sleep by signal

I want to write an C++ programm which should wait for a linux signal (millisecond resolution), but I am not able to find a possibility to achieve this. The following test code should terminate after 500ms, but it doesn't. #include…
gerum
  • 974
  • 1
  • 8
  • 21
1
vote
1 answer

std::this_thread::sleep_for() vs sleep() in main()

std::this_thread::sleep_for() Or usleep() What would be better to be used in main()? This may be very silly but i am new to C++11 features.
Rahul Das
  • 115
  • 1
  • 6
1
vote
0 answers

Why usleep affects the later code performance?

I'm new to performance analysis and I had a performance problem in my system. The code snippet is like int main() { for(int i {0}; i < 20000; ++i) { //usleep(30*1000); clock_t start = clock(); int ii = 10000000; …
ElanSaphir
  • 11
  • 1
1
vote
1 answer

usleep not working, invalid argument error

usleep just isn't waiting any time, the errno variable accuses an invalid argument is being passed on to the function, even if i use the useconds_t type I just get the same error over and over. I have no idea what's going on here, here's the file I…
1
vote
0 answers

Error using the usleep function as the compiler says " 'usleep' was not declared in this scope despite" including all needed libraries

My code is as follows: #include #include #include #include int main() { printf("test"); usleep(1000000); printf("test"); return 0; } I am being told "error: 'usleep' was not declared in…
MrMoglin
  • 29
  • 1
  • 4