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
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