wait

Linux WaitForSingleObject?

我与影子孤独终老i 提交于 2019-12-02 17:51:18
问题 Here a piece of code showing the problem //main Process* process = NULL; while(!process) { cout<<endl<<"Waiting for second process.\nPress any key"; getchar(); getchar(); process = Process::takeExisting("process"); } Process::waitEnd(process); //Problem here cout<<endl<<"second process ended"; //Process::waitEnd static void waitEnd(Process* proc) { int w = waitpid(proc->hProcess, &(proc->exitCode), WCONTINUED); Debug::error(errno," waitpid error - "); } I've tried: stop first, wait second

await Task.Delay() vs. Task.Delay().Wait()

China☆狼群 提交于 2019-12-02 17:37:25
In C# I have the following two simple examples: [Test] public void TestWait() { var t = Task.Factory.StartNew(() => { Console.WriteLine("Start"); Task.Delay(5000).Wait(); Console.WriteLine("Done"); }); t.Wait(); Console.WriteLine("All done"); } [Test] public void TestAwait() { var t = Task.Factory.StartNew(async () => { Console.WriteLine("Start"); await Task.Delay(5000); Console.WriteLine("Done"); }); t.Wait(); Console.WriteLine("All done"); } The first example creates a task that prints "Start", waits 5 seconds prints "Done" and then ends the task. I wait for the task to finish and then print

Android Wait for user input at AlertDialog to proceed

不羁岁月 提交于 2019-12-02 17:11:15
问题 I've see this subject been discussed here but can't seem to understand how to proceed. In my onCreate I have code that checks if it is the first run of the application firstRun = getPref.getBoolean("firstRun", true); . If its the first time that the app is run, an alertdialog is shown with a message saying thats there is no database installed and the user as to press the OK button to download the database. If there are no errors than pref.putBoolean("firstRun", false); and the alertdialog it

How can I make bash wait for a process to finish before continuing on with a script? [closed]

这一生的挚爱 提交于 2019-12-02 16:48:27
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I have a script that uses sed to search and replace a simple .yaml file and output a .sh file which should then be pulled in with source. My problem is that I can't figure out how to wait until sed outputs the .sh before calling source . sed -e 's/:[^:\/\/]/="/g;s/$/"/g;s/ *=/=/g' in.yaml > out.sh source out.sh

How to Wait in Objective-C and Swift

帅比萌擦擦* 提交于 2019-12-02 16:33:46
I want to change my UILabel 's text after 2 seconds. I tried setting my UILabel 's text to "A text" , and use sleep(2) and finally changing the text to "Another text" . But sleep(2) only freezes the app and "Another text" is set without displaying "A text" for 2 seconds. How may I display "A text" for 2 seconds and then show "Another text" ? Michał Zygar You can use [self performSelector:@selector(changeText:) withObject:text afterDelay:2.0]; or if you want to display it periodically, check the NSTimer class. I know I am late to this party. But I found people haven't mention thread sleep. If

Thread.sleep() implementation

你说的曾经没有我的故事 提交于 2019-12-02 16:16:37
Today I had an interview on which I asked candidate quite usual and basic question about the difference between Thread.sleep() and Object.wait() . I expected him to answer something like like this , but he said these methods basically are the same thing, and most likely Thread.sleep is using Object.wait() inside it, but sleep itself doesn't require external lock. This is not exactly a correct answer, because in JDK 1.6 this method have following signature. public static native void sleep(long millis) throws InterruptedException; But my second thought was that it's not that ridiculous. It's

Linux WaitForSingleObject?

放肆的年华 提交于 2019-12-02 11:44:16
Here a piece of code showing the problem //main Process* process = NULL; while(!process) { cout<<endl<<"Waiting for second process.\nPress any key"; getchar(); getchar(); process = Process::takeExisting("process"); } Process::waitEnd(process); //Problem here cout<<endl<<"second process ended"; //Process::waitEnd static void waitEnd(Process* proc) { int w = waitpid(proc->hProcess, &(proc->exitCode), WCONTINUED); Debug::error(errno," waitpid error - "); } I've tried: stop first, wait second ends, continue first. The problem: the second process is not child( I run it from second console ) so with

Can a thread call wait() on two locks at once in Java (6)

南楼画角 提交于 2019-12-02 11:28:32
I've just been messing around with threads in Java to get my head around them (it seems like the best way to do so) and now understand what's going on with synchronize, wait() and notify(). I'm curious about whether there's a way to wait() on two resources at once. I think the following won't quite do what I'm thinking of ( edit : note that the usual while loops have been left out of this example to focus just on freeing up two resources ): synchronized(token1) { synchronized(token2) { token1.wait(); token2.wait(); //won't run until token1 is returned System.out.println("I got both tokens back

Android Wait for user input at AlertDialog to proceed

邮差的信 提交于 2019-12-02 09:54:57
I've see this subject been discussed here but can't seem to understand how to proceed. In my onCreate I have code that checks if it is the first run of the application firstRun = getPref.getBoolean("firstRun", true); . If its the first time that the app is run, an alertdialog is shown with a message saying thats there is no database installed and the user as to press the OK button to download the database. If there are no errors than pref.putBoolean("firstRun", false); and the alertdialog it's not shown in the next runs. Now I want to introduce a ChangeLog that it is only shown on the first

Java Thread及其synchronized,wait,sleep,join,yeid,interrupt

浪子不回头ぞ 提交于 2019-12-02 09:05:48
Java SE7 API - Thread: http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#yield%28%29 参考资料: http://blog.csdn.net/lqqmisslll/article/details/54208491 一、线程的简介 当JVM启动的时候, 通常会有一个独立的非守护线程(也就是类中的main方法所在的线程).JVM会继续运行,除非发生以下情况: Runtime类的exit()方法被调用,并且安全管理者允许退出发生。 所有非守护线程都已经死了,不管是从run方法中返回的还是因为run方法中抛出了异常。 注意:当所有非守护线程都执行结束(包括主线程),那么守护线程也会退出。因为守护线程是无法脱离非守护线程而独自存在的。 二、创建线程有两种方式: 方法1:声明一个类作为Thread的子类(extends Thread),子类重写(override)Thread类的run()方法。子类的实例可以被分配和start。 //比如:该线程用来计算比指定起始值大的素数。 class PrimeThread extends Thread { long minPrime; PrimeThread(long minPrime) { this.minPrime = minPrime; }