LOL sounds like you fail your own interview On Jun 1, 8:38 pm, leo <leo.kuznet...@gmail.com> wrote: > I am trying to run following code on emulator (it's an interview > puzzle with deliberate racing condition) and I observe all threads > stuck on the first x++ and join() never executed. > > If I comment out x++ everything comes to completion... > > Is it something I do wrong or static access on dalvik-emulator is > broken somehow? > Should I file a bug? > > I have the latest sdk update for the time of writing: > > static { > try { > test(); > } catch (InterruptedException e) { > throw new Error(e); > } > } > > static int x; > > public static void test() throws InterruptedException { > Thread[] t = new Thread[5]; > for (int i = 0; i < 5; i++) { > final int k = i; > t[i] = new Thread() { > public void run() { > for (int j = 0; j < 5; j++) { > x++; > } > System.out.println("done[" + k + "]"); > } > }; > t[i].start(); > } > for (int i = 0; i < 5; i++) { > t[i].join(); > } > System.out.println("x=" + x); > }
-- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en