Questions tagged [busy-waiting]
92 questions
92
votes
1 answer
Loop doesn't see value changed by other thread without a print statement
In my code I have a loop that waits for some state to be changed from a different thread. The other thread works, but my loop never sees the changed value. It waits forever. However, when I put a System.out.println statement in the loop, it suddenly…
Boann
- 44,932
- 13
- 106
- 138
17
votes
2 answers
Spinlock vs Busy wait
Please explain why Busy Waiting is generally frowned upon whereas Spinning is often seen as okay. As far as I can tell, they both loop infinitely until some condition is met.
PMcK
- 335
- 2
- 10
10
votes
1 answer
In C, can we read from pipes without busywaiting, may be using callbacks or other ways?
I was trying to read from the STDOUT of a forked process. However, if I am reading from the pipe in an infinite for loop, it would be busy waiting even if no data is coming through the pipe (please correct me if I am wrong), and I guess there must…
nohup
- 2,805
- 1
- 19
- 45
10
votes
3 answers
Haskell: Monitor a file without polling (à la inotify in linux)
Is there a haskell library function to monitor a file without polling?
With polling i would do someting like this:
monitor file mtime handler = do
threadDelay n -- sleep `n` ns
t <- getModificationTime file
if t > mtime
then…
scravy
- 10,869
- 11
- 60
- 115
10
votes
2 answers
What is the difference between busy-wait and polling?
From the Wikipedia article on Polling
Polling, or polled operation, in computer science, refers to actively sampling the status of an external device by a client program as a synchronous activity. Polling is most often used in terms of input/output…
Aquarius_Girl
- 18,558
- 57
- 191
- 353
9
votes
2 answers
Why does ScheduledExecutorService.shutdown() uses 100% of my CPU?
I've got the following simple code:
package main;
import java.util.concurrent.*;
public class Main {
public static void main(String[] args) throws InterruptedException {
new Main();
}
public Main() throws InterruptedException…
Mosty Mostacho
- 39,610
- 14
- 86
- 115
8
votes
1 answer
Prevent MPI from busy looping
I have an MPI program which oversubscribes/overcommits its processors. That is: there are many more processes than processors.
Only a few of these processes are active at a given time, though, so there shouldn't be contention for computational…
Richard
- 44,865
- 24
- 144
- 216
5
votes
2 answers
Implementing a condition_variable to solve a multithreaded busy-wait
My program prints multiple lines of text to the console through the use of idle worker threads. The problem, however, is that the workers aren't waiting on previous workers to finish before printing the text, which results in text being inserted…
user3776022
- 209
- 3
- 10
5
votes
2 answers
Spin waits, spin loop and busy spin
Are spin waits, spin loop and busy spin a different name for the same situation?
I read different threads and they all seem related to a loop that is "busy" checking for the availability of a resource.
John Henry
- 151
- 1
- 8
5
votes
2 answers
Threads: Busy Waiting - Empty While-Loop
During our lessons in the university, we learned about Threads and used the "Busy Waiting" method for an example of a Car waiting at a TrafficLight. For this task we build three classes:
TrafficLight (implements Runnable)
Car (implements…
Kaibear
- 75
- 1
- 3
- 14
5
votes
3 answers
High throughput non-blocking server design: Alternatives to busy wait
I have been building a high-throughput server application for multimedia messaging, language of implementation is C++. Each server can be used in stand-alone mode or many servers can be joined together to create a DHT-based overlay network; the…
user2856296
3
votes
3 answers
Could a tight loop destroy cells of a microcontroller's flash?
It is well-known that Flash memory has limited write endurance, less so that reads could also have an upper limit such as mentioned in this Flash endurance test's Conclusion (3rd point).
On a microcontroller the code is typically stored in Flash,…
Jubatian
- 2,031
- 10
- 21
3
votes
4 answers
Empty loop which waits for condition (busy-waiting)
I have been spending the last 20 minutes doing research on empty loops which purpose are only to wait for a condition to become true.
I have a function called "waitForLoaded" which is a thread created by CreateThread.
The function:
void…
Thomas White
- 31
- 1
- 3
3
votes
1 answer
Alternative to time.sleep
INTRO: It is well known that the accuracy of time.sleep is OS and computation load dependent. The accuracy in Windows is very poor.
Similarly to /questions/17499837 a method can implement a busy wait using the time.clock method as an alternative to…
WOM
- 31
- 1
- 4
2
votes
1 answer
Is it better to deadlock main thread instead of busy waiting?
I have a main thread that starts multiple deamon threads listening to filesystem events.
I need to keep the main thread alive. To do so I can use a while loop, or "deadlock" it. Which is better, performance wise?
while True:
…
Julien__
- 1,864
- 1
- 10
- 22