Questions tagged [busy-loop]
19 questions
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
7
votes
2 answers
Better solution for Python Threading.Event semi-busy waiting
I'm using pretty standard Threading.Event:
Main thread gets to a point where its in a loop that runs:
event.wait(60)
The other blocks on a request until a reply is available and then initiates a:
event.set()
I would expect the main thread to…

Jonathan Rom
- 83
- 6
7
votes
2 answers
what is the different of busy loop with Sleep(0) and pause instruction?
I would like to wait on an event in my app which supposed to happen immediately, so I don't want to put my thread on wait and wake it up later.
I wonder what are the difference between using Sleep(0) and hardware pause instruction.
I cannot see any…

sramij
- 4,775
- 5
- 33
- 55
6
votes
6 answers
Why blocking instead of looping?
What are some reasons why writing the following piece of code is considered bad practice?
while (someList.isEmpty()) {
try {
Thread.currentThread().sleep(100);
}
catch (Exception e) {}
}
// Do something to the list as soon as…

BJ Dela Cruz
- 5,194
- 13
- 51
- 84
4
votes
5 answers
Good way to create an idle loop in C#?
I have an app it sets up a FileSystemWatcher. It should run indefinitely.
What is the best way to have it run in an idle loop?
I'm currently doing
FileSystemWatcher watch = ... //setup the watcher
watch.EnableRaisingEvents = true;
while (true)
{
…

Vinko Vrsalovic
- 330,807
- 53
- 334
- 373
3
votes
1 answer
Is polling a receive-block in erlang good practice?
I'm new to Erlang and have a question about the receive block. I'm trying to receive one or more message(s) from a child process that is performing a task. The way I found out how to receive a message is by using a receive-block.
E.g.
main() ->
…

iTunes
- 143
- 5
3
votes
5 answers
Why does a busy loop take 100% of the CPU?
Why does a busy loop often uses 100% of the cpu time while loops that implement complex algorithms would use much much less?
thanks :)

Idov
- 5,006
- 17
- 69
- 106
3
votes
5 answers
Get rid of busy waiting during asynchronous cuda stream executions
I looking for a way how to get rid of busy waiting in host thread in fallowing code (do not copy that code, it only shows an idea of my problem, it has many basic bugs):
cudaStream_t steams[S_N];
for (int i = 0; i < S_N; i++) {
…

kokosing
- 5,251
- 5
- 37
- 50
3
votes
2 answers
Variable performance of busy wait loop?
I am evaluating the performance of a busy wait loop for firing events at consistent intervals. I have noticed some odd behavior using the following code:
#include
#include
#include
#include
int…

Rakurai
- 974
- 7
- 15
2
votes
1 answer
Avoiding busy loop with boost::asio::io_service run
I am implementing some asio operations using boost,
I've encountered an interface problem, whom which I am not receiving 'handlers' in initialization, but right after,
This forces me to write a 'busy' loop, what I'd like to do is have the io_service…

Alon
- 1,776
- 13
- 31
2
votes
0 answers
Intel's PAUSE instruction and possible memory order violation
Possible Duplicate:
pause instruction in x86
Intel's Optimization Reference Manual has the following to say about spin-wait loops:
3.4.1.2 Spin-Wait and Idle Loops
The Pentium 4 processor introduces a new PAUSE instruction; the instruction is
…

NPE
- 486,780
- 108
- 951
- 1,012
1
vote
0 answers
Is it bad practice to use Thread.yield() when busy-looping?
I have a thread busy-looping until my ServerSocket object binds to a port before doing any read/write operation.
new Thread(() -> {
while (!server.isBound()) {
Thread.yield(); // hmm ... any better alternative????
}
while…

Doga Oruc
- 783
- 3
- 16
1
vote
2 answers
Is there a standard function to busy wait for a condition or until a timeout
I need to wait in my program for a subsystem. In different places a have to wait for different conditions. I know I could also make use of threads and conditions variables. But since the subsystem (bare metal programmed in C) is connected via…

florgeng
- 856
- 1
- 9
- 17
1
vote
1 answer
Why does busy-wait of less than 15ms are inconsistent?
I am doing simulation project where i have hundred of CPU-Bound jobs running for 10 to 50 milliseconds. The Job is a Runnable object with specified running-time for which the job will keep CPU busy. There are 10 threads waiting in a thread pool for…

Faisal Bahadur
- 498
- 3
- 19
1
vote
2 answers
Is busy wait inconsistent?
I want a busy wait loop for a specific amount of time and I tested the following java code, which gives different outputs on different runs (sometimes). Most of the time it gives 16 and 0. It means one can not trust a busy wait. What is the…

Faisal Bahadur
- 498
- 3
- 19