I have a litte race condition in my current android instrumentation test. What I want is:
- T1: Start Thread T2
- T2: Do something
- T1: Join with T2
With step 1 and 3 being Android live cycle events. But because in the instrumentation test everything happens very fast I get:
- T1: Start Thread T2
- T1: Join with T2 (which turn out to be a no-op)
- T2: Do something
Sure I could add a few sleeps to get the desired behaviour but I wonder if there is better way to do it. i.E. is there a way to make sure the thread which was just start ()
-ed did actually start for good and is not still sitting in some scheduling queue awaiting start-up.
(Andy boy, do I miss Ada's rendezvous based multitasking)
And to answer mat's question:
if (this.thread != null && this.thread.isAlive ())
{
this.stop.set (true);
try
{
this.thread.join (1000);
}
catch (final InterruptedException Exception)
{
android.util.Log.w (Actor.TAG, "Thread did not want to join.", Exception);
} // try
} // if
As I said: no-op when because the thread has not started yet.