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
53
votes
13 answers

What is a practical use for PHP's sleep()?

I just had a look at the docs on sleep(). Where would you use this function? Is it there to give the CPU a break in an expensive function? Any common pitfalls?
alex
  • 479,566
  • 201
  • 878
  • 984
38
votes
7 answers

c++, usleep() is obsolete, workarounds for Windows/MingW?

I already found out with another question that Windows/MingW doesn't provide the nanosleep() and setitimer() alternatives to the obsolete usleep(). But my goal is to fix all warnings that cppcheck gives me, including the usleep() style warnings. So,…
blubberbernd
  • 3,641
  • 8
  • 35
  • 46
37
votes
6 answers

implicit declaration of function usleep

gcc (GCC) 4.6.3 c89 I am trying to use usleep. However, I keep getting the following warning: implicit declaration of function usleep I have included the unistd.h header file. The man pages mentions something about this. But I am not sure I…
ant2009
  • 27,094
  • 154
  • 411
  • 609
24
votes
5 answers

Difference among sleep() and usleep() in PHP

Can any body explain me what is the difference among sleep() and usleep() in PHP. I have directed to use following scripts to do chat application for long pulling but in this script I am getting same effect using usleep(25000); or without…
MD SHAHIDUL ISLAM
  • 14,325
  • 6
  • 82
  • 89
14
votes
3 answers

time delay in C. usleep

I'm developing the game server, which is written on C. And I need to develop a cycle with a certain frequency (50 times per second) to perform an algorithm. The problem is that I can't pause the program for an exact time interval - 20000…
Andrew
  • 143
  • 1
  • 1
  • 6
14
votes
4 answers

Equivalent of usleep() in CUDA kernel?

I'd like to call something like usleep() inside a CUDA kernel. The basic goal is to make all GPU cores sleep or busywait for a number of millesconds--it's part of some sanity checks that I want to do for a CUDA application. My attempt at doing this…
solvingPuzzles
  • 8,541
  • 16
  • 69
  • 112
12
votes
8 answers

Sleeping in a Thread (C / POSIX Threads)

I am developing a multithreaded application that makes use of POSIX Threads. I am using threads for doing a periodical job and for that purpose I am using usleep(3) to suspend thread execution. My question is how can I cancel usleep() timer from the…
Emre Yazici
  • 10,136
  • 6
  • 48
  • 55
11
votes
7 answers

Effect of usleep(0) in C++ on Linux

The documentation for usleep states that calling usleep(0) has no effect. However, on my system (RHEL 5.2) running the small snippets of C++ code below, I find that it actually appears to have the same effect as usleep(1). Is this to be expected,…
Matt Dunn
  • 5,106
  • 6
  • 31
  • 55
8
votes
2 answers

why use usleep and not sleep

I was reading a code of application and something caught my attention. The code was : usleep(6*1000*1000). I understand that they use this format for readability issues. I think that both sleep and usleep use the nanosleep function, so my question…
Loay Ashmawy
  • 677
  • 1
  • 7
  • 26
5
votes
1 answer

Haskell: why is usleep + threaded compile option more precise than threadDelay?

I wrote a test program in Haskell on the Raspberry Pi that plays a delightful tune on a buzzer connected to a GPIO pin. Here are the imports I used: import qualified Control.Concurrent as C import qualified Control.Monad as M import…
Gord
  • 155
  • 7
5
votes
2 answers

implicit declaration of function ‘usleep’

So i've been looking stuff about usleep() and all I have found to get rid of this is #define which i have done... Any ohter suggestion? I need to get rid of this warning... Or any ideas on how to use sleep with miliseconds. #define…
user3785202
  • 67
  • 1
  • 1
  • 6
4
votes
1 answer

Throttle cURL using usleep()

I'm using a web service to send 100's of http posts. However, the service only allows 5 per second. I'm wondering if the usleep command is the best way to do this. For example: foreach($JSONarray['DATABASE'] as $E) { $aws = curl_init(); …
johnwhitney
  • 93
  • 1
  • 3
  • 12
4
votes
1 answer

PHP Output Buffer Benchmark (microtime inaccurate when used with usleep?)

I post a strange behavior that could be reproduced (at least on apache2+php5). I don't know if I am doing wrong but let me explain what I try to achieve. I need to send chunks of binary data (let's say 30) and analyze the average Kbit/s at the end…
nunja
  • 41
  • 1
  • 3
4
votes
0 answers

Python sleep until time without busy loop

Let's say I want to make an event reminder in Python. It would read a file on startup containing a list of events (meetings, birthdays, etc), figure out which one is soonest, and then do something like time.sleep(1e7). Actually, that doesn't work:…
Mark VY
  • 1,489
  • 16
  • 31
4
votes
3 answers

C++ While loop, usleep()/sleep() how not to use 90% of CPU? (Ubuntu 12.04)

Suppose I have C++ code such as #include "myheaderfiles.h" //..some stuff //...some more stuff int main() { double milliseconds; int seconds; int minutes; int timelimit=2; ... ... //...code here that increments …
ChumbiChubaGo
  • 968
  • 2
  • 9
  • 15
1
2 3 4 5 6 7