Questions tagged [busy-waiting]

101 questions
1
vote
4 answers

Wait for system time to continue application

I've written a class to continue a started JAVA application if the current second is a multiple of 5 (i.e. Calender.SECOND % 5 == 0) The class code is presented below, what I'm curious about is, am I doing this the right way? It doesn't seem like an…
saccu
  • 117
  • 1
  • 2
  • 7
1
vote
2 answers

wont infinite loop waste cpu resource?

I am planning to use boost::lockfree::queue for my multi threaded application. A boost example illustrates lockfree queue consumption like this: boost::atomic done (false); void consumer(void) { int value; while (!done) { while…
rahman
  • 4,820
  • 16
  • 52
  • 86
1
vote
1 answer

Alternative to Busy-Wait Structure Python

In a program I am writing, I have a small problem. I would like to be able to know when an element has been created but do not have access to the element's library. The library provides a function that returns True or False when it is finished and…
NAlex
  • 11
  • 2
1
vote
1 answer

Threading and busy-waiting in scheme

I'm writing a scheme program that allows a user to create planets that follow gravitational laws. For the assignment, I have to alter the code to avoid busy waiting and also create a new thread for each planet, or every time that the mouse is…
1
vote
1 answer

Go times out on sleep but not on busy-wait

In Go, I can use time.After to time out a sleeping function, but I can't do the same to a function that is busy-waiting (or working). The following code returns timed out after one second, and then hangs. package main import ( "fmt" …
Matthew Piziak
  • 3,430
  • 4
  • 35
  • 49
1
vote
2 answers

Using volatile boolean variable for busy waiting

The question arises after reading some codes written by another developers, so I did some research and I found article by Andrei Alexandrescu. In his article he says that it is possible to use volatile boolean variable for busy waiting (see the…
axe
  • 2,331
  • 4
  • 31
  • 53
1
vote
2 answers

How can I write a C program to execute for a certain number of processor seconds?

I need a C program that would execute for a precise number of CPU seconds passed in as a parameter. I need such a program in order to test code that monitors a process' CPU usage. Example: busywait x Should run for x seconds on my processor.
Will Brode
  • 1,026
  • 2
  • 10
  • 27
1
vote
1 answer

how to wait effectively on a set of semaphore?

I'm using semaphores with shared-memory for communicating between multi-producers and multi-clients. There are two main kinds of semaphores in my system, which are "stored semaphores" and "processed semaphores". The system run as following: …
khanhhh89
  • 317
  • 5
  • 19
1
vote
2 answers

How to do things while the page is busy with asp.net?

I have an asp.net web application that when you click a button it excecutes all my stuff but it is slow it takes 10 to 15 seconds to work and i dont want users to spam click the button while the site is busy. So my plan was to disable the button and…
FLG
  • 163
  • 2
  • 10
0
votes
1 answer

CPU time sleep instead of wall-clock time sleep

Currently, I have the following Rust toy program: use rayon::prelude::*; use std::{env, thread, time}; /// Sleeps 1 seconds n times parallely using rayon fn rayon_sleep(n: usize) { let millis = vec![0; n]; millis .par_iter() …
Román Cárdenas
  • 492
  • 5
  • 15
0
votes
0 answers

Busy-waiting Future in Rust Tokio

I want to implement a Future that busy-waits on its completion. According to this link, this is one option impl Future for Delay { type Output = &'static str; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<&'static…
Samuel Hapak
  • 6,950
  • 3
  • 35
  • 58
0
votes
4 answers

Inconsistent busy waiting time in c

I have a character that should "eat" for 200 microseconds, "sleep" for 200 microseconds, and repeat, until they die, which happens if they haven't eaten for time_to_die microseconds. In the code snippet in function main indicated below, the struct…
kooru_hi
  • 43
  • 5
0
votes
1 answer

test_and_set makes the thread deadlock

#include using namespace std; int cnt=0; int locked=0; int test_and_set(int * lock){ int temp=*lock; *lock=1; return temp; } void cntOnes(int t){ while(test_and_set(&locked)); for(int i=0;i<2000;i++){ …
0
votes
1 answer

Android: Wait for userinput but set a timeout

In my application the user is prompted with an exercise and he has 5 seconds to solve it, if he does not respond in time, the next exercise should be shown. My question is: What would be the best way to implement such a behaviour in Android? I have…
0
votes
1 answer

Are Java synchronised method/statements and locks (e.g. re-entrant lock) busy waiting mechanisms?

I am learning concurrency in Java, and came to know about semaphores, which can be used for synchronisation without busy waiting. Now, I'm wondering if Java synchronised method/statements and locks (e.g. re-entrant lock) are busy waiting…
Rajat Aggarwal
  • 392
  • 3
  • 16