java - Can this code have race condition? -


    public static void deletelast(vector list) {     int lastindex = list.size() - 1;//line 2     list.remove(lastindex);         // line 3 } 

i known vector threadsafe in java can case happen

let's in case has list.size()=10

thread calls deletelast , @ line 2 lastindex = 9 .it stops reason

thread b call deletelast , @ line 2 lastindex = 9.it goes line 3 , list has 9 elements

thread wakes , goes line 3 tries remove object @ index 9 doesn't exist , have exception here

sure. you've correctly identified race condition.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -