Questions tagged [busy-waiting]
101 questions
106
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
- 48,794
- 16
- 117
- 146
20
votes
3 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
- 393
- 1
- 2
- 11
16
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
- 21,790
- 65
- 230
- 411
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
- 3,105
- 3
- 27
- 52
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
- 11,904
- 14
- 72
- 127
9
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
- 56,349
- 34
- 180
- 251
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
- 42,742
- 16
- 96
- 123
8
votes
1 answer
Why is the compiler allowed to optimize out this busy waiting loop?
#include
#include
#include
int main()
{
std::atomic ready = false;
std::thread threadB = std::thread([&]() {
while (!ready) {}
printf("Hello from B\n");
});
…

Ashot
- 10,807
- 14
- 66
- 117
8
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
- 301
- 3
- 9
6
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
- 95
- 1
- 2
- 15
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
- 217
- 3
- 12
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
4
votes
5 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
- 41
- 1
- 1
- 3
3
votes
1 answer
Google Colab - Completed but still running?
I have a large dataset (that I am trying to run. The cell has not generated an output; however, it currently says 'completed at [time]'. The cell still appears to be running and the is a message saying 'waiting for python 3 to Compute Engine…

ConnXu
- 31
- 2
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,171
- 16
- 22