sleep

nanosleep high cpu usage?

倖福魔咒の 提交于 2019-11-29 10:11:57
问题 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) { nanosleep(&sleepTime, &returnTime); } return 0; } (Yes, I realise this program does nothing) If I compile this and run it on an openSUSE 10.3 machine (2.6.22.19-0.2-default), the

Thread sleep and precise timing [duplicate]

帅比萌擦擦* 提交于 2019-11-29 07:03:48
This question already has an answer here: How accurate is Thread.sleep? 3 answers I am making a code where I want definite precision in my timing. I use a robot to make some actions, then I use Thread.sleep(some_time) for some_time to be elapsed between the actions. But I don't get best results because as I search it, sleep is not accurate. What would be the best way to accomplish this? I mean simulate Thread.sleep with other methods. Timing in modern OSes is never precise, unless you use a language/framework that was explicitly designed for this. You can however work with a reasonable

How can I create a sleep function in 16bit MASM Assembly x86?

◇◆丶佛笑我妖孽 提交于 2019-11-29 06:23:31
I am trying to create a sleep/delay procedure in 16bit MASM Assembly x86 that will, say, print a character on the screen every 500ms. From the research I have done, it seems that there are three methods to achieve this - I would like to use the one that uses CPU clock ticks. Please note I am running Windows XP through VMWare Fusion on Mac OS X Snow Leopard - I am not sure if that affects anything. Could someone please point me in the right direction, or provide a working piece of code I can tweak? Thank you! The code I have found is supposed to print 'A' on the screen every second, but does

Detect Gesture with Phone sleeping [closed]

末鹿安然 提交于 2019-11-29 05:22:37
I am developing an SOS android app. I want to detect a gesture (for example several touches on screen) if the phone is in mode sleep/standby, and start a send of help request (for example send a sms). How can I detect this gesture? Someone that can help me? Thank you ---SOLUTION---- I found the solution here and this is my code: 1)in the main activity getApplicationContext().startService(new Intent(this, UpdateService.class)); 2)I create a service public class UpdateService extends Service { @Override public void onCreate() { super.onCreate(); // register receiver that handles screen on and

Playing music in sleep/standby mode in Android 2.3.3

邮差的信 提交于 2019-11-29 05:21:02
I am trying to develop a simple media player to play mp3's of the sdcard/music directory for Android 2.3.3. The problem is when I hit the power button or when the device goes to sleep, the music stops. From googling, and searching stackoverflow, I found that I need to use the wake lock options, but no matter what I do, the music stops when the device goes to sleep (Pressing F7 on the emulator stops the music as well). Since I've been fighting this for way too long, I thought I'd ask for help. I would sincerely appreciate any input. Thanks. Here's my code: FileInputStream fis = new

JavaScript sleep [duplicate]

断了今生、忘了曾经 提交于 2019-11-29 04:23:55
This question already has an answer here: What is the JavaScript version of sleep()? 74 answers Yes, I know - that question has thousands of answers. please, don't tell me about setTimeout method because - yes, everything is possible with that but not so easy as using sleep() method. For example: function fibonacci(n) { console.log("Computing Fibonacci for " + n + "..."); var result = 0; //wait 1 second before computing for lower n sleep(1000); result = (n <= 1) ? 1 : (fibonacci(n - 1) + fibonacci(n - 2)); //wait 1 second before announcing the result sleep(1000); console.log("F(" + n + ") = "

To make a choice between ManualResetEvent or Thread.Sleep()

烈酒焚心 提交于 2019-11-29 02:16:05
I am not sure which strategy to adopt...I am focusing on my operation getting completed, but I'd also like to keep performance issues to a min too...there is a method called Execute() which has to wait (run synchronously) until an operation completes. This operation happens on another thread. There are 2 ways to implement the same thing... By using ManualResetEvent void Execute() { taskHandle = new ManualResetEvent(false); . . //delegate task to another thread . . taskHandle.WaitOne(); } OR By using a simple while construct void Execute() { . . //delegate task to another thread . . while (

Pause an Android App with Phonegap

落花浮王杯 提交于 2019-11-29 01:53:15
Is there any way to programmatically pause an Android app in Phonegap? I would like to mimic the behavior that occurs when you hit the HOME button. I've already had to overwrite the back button handler using this , and while in most cases I want it to do my action, when in a particular state the user would expect the app to minimize, and I want to replicate this behavior. Keep in mind, on Android this is not the same as closing the app. That is quite easy to do with device.exitApp(); but I would like it to remember its state and keep running in the background. Especially if there's still an

Android Sleep/Wait/Delay function

北战南征 提交于 2019-11-29 01:31:53
first of all, I'm a beginner to android world so please apologize me if it is stupid question.. I'm trying to do following: Enable Mobile Data Wait for 10 seconds a. check if Mobile got IP address (data connected sucessfully) b. if Not connected,Disable Data c. Go to step 1 And these steps 1 to 3 are getting executed in For loop for User Given number of retries. Now my problem is: I'm stuck at step No. 2. I'm unable to make waitfor(int seconds) function. I tried using Runnable PostDelayed method but it is not giving me required output. for(retry = UserChoice; retry > 0 && !isDataAvailable ;

SwitchToThread vs Sleep(1)

心已入冬 提交于 2019-11-29 01:25:12
I'm wondering what's the actual difference between calling Thread.Sleep(1) and calling SwitchToThread (if we ignore that it's currently not exposed by the BCL). Joe Duffy mentions in his post that: "The kernel32!SwitchToThread API doesn't exhibit the problems that Sleep(0) and Sleep(1) do." (regarding the scheduler's behavior) Why won't Sleep behave exactly like SwitchToThread? Why this differentiation exist, and for what is it good for? (if at all..) There are two differences. The first is mentioned in the MSDN docs for SwitchToThread : The yield of execution is limited to the processor of