Questions tagged [thread-sleep]

The .net Thread.Sleep(...) method suspends the caller for a specified amount of time.

A call to Thread.Sleep(n) has no side effects, and it will not return until at least n milliseconds have elapsed.

References

815 questions
15
votes
3 answers

Python threading interrupt sleep

Is there a way in python to interrupt a thread when it's sleeping? (As we can do in java) I am looking for something like that. import threading from time import sleep def f(): print('started') try: sleep(100) …
Vadim Volodin
  • 377
  • 1
  • 2
  • 14
15
votes
5 answers

Is it Really Busy Waiting If I Thread.Sleep()?

My question is a bit nit-picky on definitions: Can the code below be described as "busy waiting"? Despite the fact that it uses Thread.Sleep() to allow for context switching? while (true) { if (work_is_ready){ doWork(); } …
urig
  • 16,016
  • 26
  • 115
  • 184
14
votes
5 answers

Thread sleep/wait until a new day

I'm running a process in a loop which has a limit on the number of operations it does per day. When it reaches this limit I've currently got it checking the the time in a loop to see if it a new date. Would the best option be to: Keep checking the…
finoutlook
  • 2,523
  • 5
  • 29
  • 43
14
votes
2 answers

Put Android to sleep for testing

I'm creating an alarm app and currently have issues dealing with the Wakelock (or perhaps it's something else), to make the alarms work when the phone is asleep. However, my question isn't actually about the Wakelock, but rather about how to make…
Phil
  • 305
  • 1
  • 3
  • 13
14
votes
3 answers

Sleeping less than a second in OCaml

The Unix.sleep function can suspend the program for whole seconds, but how can you suspend it for less than a second?
Matthew Piziak
  • 3,430
  • 4
  • 35
  • 49
13
votes
2 answers

why does a conditional variable fix our power consumption?

We were working on our audio player project on mac and noticed that the power usage was so high (about 7x that of google chrome doing the same workload.) I used xcode's energy profiling tool, one of the problems was we had too much cpu-wake…
Bill Yan
  • 3,369
  • 4
  • 27
  • 42
13
votes
2 answers

Make JavaFX wait and continue with code

Basically I am trying to make a short effect using JavaFX. I have the shape of a heart (added together from two circles and a polygon) that I can vary in size using the double value p. "Standart Size" would be p = 1.0;. I am trying to add a pumping…
Maverick283
  • 1,284
  • 3
  • 16
  • 33
12
votes
2 answers

Is it okay to use Thread.sleep() in a loop in Java, to do something at regular intervals?

I have read some threads that said that calling Thread.sleep() in a loop is problematic and is a serious performance issue. But in some cases it seems the most natural thing to do. For example if I want my application to do something every 3 minutes…
Alexandru Chirila
  • 2,274
  • 5
  • 29
  • 40
12
votes
2 answers

Do sleep functions sleep all threads or just the one who call it?

I am programming with pthread on linux(Centos)? I wanna to threads sleep a short time to wait for something. I am trying to use sleep(), nanosleep(), or usleep() or maybe something can do that. I want to ask that: Do sleep functions sleep all…
Nick Dong
  • 3,638
  • 8
  • 47
  • 84
11
votes
3 answers

What's the most CPU-efficient way to "waste time" in a thread?

I have a number of threads (100's) that each execute for a few seconds at a time. When they are executing, they spend a significant amount of that time waiting for a response from another system (a serial device). I am mindful that having 100…
rossmcm
  • 5,493
  • 10
  • 55
  • 118
11
votes
2 answers

How can I await at least specified amount of time with Awaitility?

I my test class I really need to sleep for some amount of time. It's an integration test involving periodic remote call. for (int i = 0; i < 16; i++) { // sleep some... should sleep some... Thread.sleep((int) TimeUnit.MINUTES.toMillis(4L));…
Jin Kwon
  • 20,295
  • 14
  • 115
  • 184
11
votes
5 answers

Thread.sleep waits more than expected

The following code: long msBefore = System.currentTimeMillis(); //Thread.currentThread().setPriority(Thread.MAX_PRIORITY); try {Thread.sleep(200); } catch (InterruptedException e){} System.out.println("Time: " + (System.currentTimeMillis() -…
Muhammad Hewedy
  • 29,102
  • 44
  • 127
  • 219
11
votes
2 answers

SystemClock.sleep() vs. Thread.sleep() while waiting for a semaphore loop

In order to synchronize/queue access to a shared resource, I am about to use a Semaphore, aided by a wait loop. In order not to run into CPU pegging, I would like to sleep() a little bit inside that while loop. I searched the…
srf
  • 2,410
  • 4
  • 28
  • 41
11
votes
2 answers

How to sleep in the Linux kernel space?

I have a kernel thread which is assigned on a specific CPU with FIFO and highest priority. This thread sleeps from time to time but the time interval must be as precise as possible. So with this in mind what would be the most precise way to sleep in…
Andreea Tanasa
  • 111
  • 1
  • 1
  • 5
11
votes
6 answers

Thread.Sleep() without freezing the UI

First off, I am a beginner in C# and I would like to make this: class2.method_79(null, RoomItem_0, num, num2, 0, false, true, true); System.Threading.Thread.Sleep(250); class2.method_79(null, RoomItem_0, num, num4, 0, false, true,…
user3640047
  • 177
  • 1
  • 2
  • 7
1
2
3
54 55