sleep

Sleep function in c in windows. Does a function with better precision exist?

I was wondering if anyone knew of a better sleep function that could be used in windows in c, other than Sleep(), which takes a millisecond input and only guarantees that the input is the minimum amount of time that elapses. I am passing in 1 millisecond, but actually getting a 15-16 millisecond delay. Is there any way to accurately set ...

Javascript sleep

Is any better way than this function to make a sleep in javascript, or should I just use that function? (taken from here) function pausecomp(millis) { var date = new Date(); var curDate = null; do { curDate = new Date(); } while(curDate-date < millis); } This is not a dupe of http://stackoverflow.com/questions/758688/sleep-in...

Delphi - adjusting thread sleep time

Hi. There are several threads in my application that work in the background. They connect to database and execute some time consuming select queries. In most of cases these queries return only several records. From time to time, however, they may return tens of thousands records. All these are then processed in a loop. Because such sit...

waking up one thread from another

I am using .NET (C#). if I have 2 threads running T1 and T2 and T1 is like this: while (true) { dosomething(); //this is a very fast operation sleep(5 seconds); } at the same time T2 is doing something completely different however from time to time it needs to give T1 a kick such that it wakes up from the sleep even though the s...

Get a Unix script to run at exactly the same time every time

I am writing a script to capture disk usage on a system (yes, I know there is software that can do this). For database reporting purposes, I want the interval between data points to be as equal as possible. For example, if I am polling disk usage every 10 minutes, I want every data point to be YYYY-MM-DD HH:[0-5]0:00. If I'm am pollin...

Bash date/time arithmetic

I have a little Bash script which suspends the computer after a given number of minutes. However, I'd like to extend it to tell me what the time will be when it will be suspended, so I can get a rough idea of how long time I have left so to speak. #!/bin/sh let SECS=$1*60 echo "Sleeping for" $1 "minutes, which is" $SECS "seconds." slee...

Sleep OS X from Java

Hi, Really simple little function, but does anyone know how to sleep OS X from Java? Cheers ...

Using Thread.Sleep() in a Windows Service

I'm writing a windows service that needs to sleep for long periods of time (15 hrs is the longest it will sleep, 30 mins is the shortest). I'm currently using Thread.Sleep(calculatedTime) to put my code into sleep mode. Is Thread.Sleep the best option or should I be using a timer? I've been googling this for a while and can't find a c...

Is there a minimum wait time in between twitter messages?

Hello all, Consider this: require 'Twitter.class.php'; $tweet = new Twitter("username", "password"); foreach($comment as $key => $value) { $link = $db->get_row("sql query"); //sleep(10;) $tweet->update('$link'); } } This makes a new twitter message for every loop, the loop happens about 10 times and I e...

How to get a unix script to run every 15 seconds?

I've seen a few solutions, including watch and simply running a looping (and sleeping) script in the background, but nothing has been ideal. I have a script that needs to run every 15 seconds, and since cron won't support seconds, I'm left to figuring out something else. What's the most robust and efficient way to run a script every 15...

<100uS accurate sleeps on Windows CE

Is it possible to sleep for an amount of time that will be accurate to less than 100 microseconds on Windows CE? The less jitter the better - ideally we'd like single digit microsecond response times. What we really want is a 5ms timer with very low jitter - although the Windows CE WaitFor[Single|Multiple]Objects and Sleep APIs work in ...

Using sleep within iPhone apps (esp. with UINavigationController)

Hi, I'm pretty new to iPhone development but I'm close to releasing my first app (related to a website I run). The app requires a very large database and as such I've decided to store only the most commonly used data locally, retrieving the other data via a JSON web service call from the database my website runs off. Whilst performing O...

Force a Different Thread to Sleep

So I have a program that serves as a sort of 'shell' for other programs. At its core, it gets passed a class, a method name, and some args, and handles the execution of the function, with the idea of allowing other programmers to basically schedule their processes to run on this shell service. Everything works fine except for one issue...

Make AVFoundation framework not fading when screen fades

Hi I am implementing some audiobooks for iPhone. I used AVFoundation. Something like this: NSString *path = [[NSBundle mainBundle] pathForResource:@"intro" ofType:@"mp3"]; player=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; I have a problem. When the screen goes dark (single audio files ...

OS X Process control

I'm writing a process-controller kernel extension for leopard. The application enables me to suspend process's with SIGSUS and to make the computer sleep. My problem is when an application that uses video / audio (e.g iTunes or GarageBand) is suspended and then I try to make the computer sleep, the sleep process waits on the audio / vide...

When does Java's Thread.sleep throw InterruptedException?

When does Java's Thread.sleep throw InterruptedException? Is it safe to ignore it? I am not doing any multithreading. I just want to wait for a few seconds before retrying some operation. ...

For a windows service, which is better, a wait-spin or a timer?

This question about Timers for windows services got me thinking: Say I have (and I do) a windows service thats waiting on a WaitHandle and when woken, it dives into a wait-spin like I have shown below in a flowchart I'm curious if using a timer would be better than a wait-spin loop (sometimes called a spin-wait). I'll be honest, I'v...

ManualResetEvent vs. Thread.Sleep

I implemented the following background processing thread, where Jobs is a Queue<T>: static void WorkThread() { while (working) { var job; lock (Jobs) { if (Jobs.Count > 0) job = Jobs.Dequeue(); } if (job == null) { Thread.Sleep(1); ...

nanosleep high cpu usage?

I noticed that a little test program which calls nanosleep is showing a huge difference in CPU usage when run on Linux machines with a kernel newer than 2.6.22. #include <time.h> int main (void) { struct timespec sleepTime; struct timespec returnTime; sleepTime.tv_sec = 0; sleepTime.tv_nsec = 1000; while (1) { ...

How to do an active sleep?

I am running some profiling tests, and usleep is an useful function. But while my program is sleeping, this time does not appear in the profile. eg. if I have a function as : void f1() { for (i = 0; i < 1000; i++) usleep(1000); } With profile tools as gprof, f1 does not seems to consume any time. What I am looking is a ...