by ragnot · 3y ago · 0 comments
tl;dr: Remember that the "new" operator does two operations: allocates memory and fills in the memory with the data. Now, if you have two threads (A & B):
- A allocates memory and then gets pre-empted
- B will pass the null pointer check and attempt to use the non-filled in memory block
That's the part I missed : the first null check can be skipped if the memory is allocated but the constructor hasn't been executed.