thread-sleep

How to install a reoccurring timer function?

浪子不回头ぞ 提交于 2019-12-23 04:34:11
问题 Is there a simple way to install a regularly occurring timer function with C++/stdlib? I would like to get rid of the loop: using namespace std::chrono; // literal suffixes auto tNext = steady_clock::now(); while (<condition>) { std::this_thread::sleep_until(tNext); tNext = tNext + 100ms; ... That function will run in its own thread. 回答1: I'm guessing what you want is this int i = 10; auto pred = [i]() mutable {return i--;}; auto print = []{cout << "." << endl;}; timer t{500ms}; t.push({print

How to install a reoccurring timer function?

让人想犯罪 __ 提交于 2019-12-23 04:34:01
问题 Is there a simple way to install a regularly occurring timer function with C++/stdlib? I would like to get rid of the loop: using namespace std::chrono; // literal suffixes auto tNext = steady_clock::now(); while (<condition>) { std::this_thread::sleep_until(tNext); tNext = tNext + 100ms; ... That function will run in its own thread. 回答1: I'm guessing what you want is this int i = 10; auto pred = [i]() mutable {return i--;}; auto print = []{cout << "." << endl;}; timer t{500ms}; t.push({print

Java Wake Sleeping Thread

笑着哭i 提交于 2019-12-22 05:55:47
问题 I did some reading of other post but didn't find an exact answer to what I'm looking for, so I hope someone can give some some clarification. I have a program that will run for some time. I have some threads that run in the back ground that perform various tasks, to keep things simple let think of 3 threads. ThreadA performs a task every 10 seconds, where ThreadB does something every 30 seconds and ThreadC does something every 5 mintues. I don't use busy waiting, and put the threads to sleep

Java Wake Sleeping Thread

痞子三分冷 提交于 2019-12-22 05:55:10
问题 I did some reading of other post but didn't find an exact answer to what I'm looking for, so I hope someone can give some some clarification. I have a program that will run for some time. I have some threads that run in the back ground that perform various tasks, to keep things simple let think of 3 threads. ThreadA performs a task every 10 seconds, where ThreadB does something every 30 seconds and ThreadC does something every 5 mintues. I don't use busy waiting, and put the threads to sleep

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

杀马特。学长 韩版系。学妹 提交于 2019-12-21 07:38:53
问题 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 threads executing at once could be a resource hog so I actually limit the number of threads that can start at any one time. It occurs to me though that there must be good and bad ways of waiting for an external event inside a thread. Is this approach CPU

Swing JForm freezes until an action is finished [duplicate]

∥☆過路亽.° 提交于 2019-12-20 06:37:34
问题 This question already has an answer here : swing window getting frozen ,not displaying content (1 answer) Closed 5 years ago . I want to create a Java application that visualizes merge sort using swing components. So far I've written this: import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Random; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; public class

Why Thread.sleep() doesn't work accordingly in JavaFX?

ε祈祈猫儿з 提交于 2019-12-20 06:25:16
问题 When i am using JavaFX, the sleep function won't work accordingly. Like in this code: public class Controller { @FXML private Label label; @FXML private Button b1; public void write() throws InterruptedException { label.setText("FIRST TIME"); for(int i=1;i<=5;i++) { System.out.println("Value "+i); label.setText("Value "+i); Thread.sleep(2000); } label.setText("LAST TIME"); } when the Button b1 is pressed the write function is called. Now, in the console "Value + i" is being printed after 2

Thread.Sleep(0) doesn't work as described?

霸气de小男生 提交于 2019-12-19 16:54:22
问题 I am currently reading this excellent article on threading and read the following text: Thread.Sleep(0) relinquishes the thread’s current time slice immediately, voluntarily handing over the CPU to other threads. I wanted to test this and below is my test code: static string s = ""; static void Main(string[] args) { //Create two threads that append string s Thread threadPoints = new Thread(SetPoints); Thread threadNewLines = new Thread(SetNewLines); //Start threads threadPoints.Start();

android game loop vs updating in the rendering thread

放肆的年华 提交于 2019-12-18 10:37:11
问题 I'm making an android game and am currently not getting the performance I'd like. I have a game loop in its own thread which updates an object's position. The rendering thread will traverse these objects and draw them. The current behavior is what seems like choppy/uneven movement. What I cannot explain is that before I put the update logic in its own thread, I had it in the onDrawFrame method, right before the gl calls. In that case, the animation was perfectly smooth, it only becomes choppy

Pausing Swing GUI

坚强是说给别人听的谎言 提交于 2019-12-18 09:52:40
问题 Hy! So I'm starting with netbeans java gui development and I have run into this problem: I have made a window with a button and a text field. When the user clicks the button I want the text field to start typing itself with a delay. So for example: textfield.text=h wait(1) sec textfield.text=he wait(1) sec textfield.text=hel wait(1) sec textfield.text=hell wait(1) sec textfield.text=hello I have already tried with Thread.sleep() , but in the example above it waits 4 seconds or so and after