3 ms·
This paper will help a lot: https://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf https://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf tl;dr: Re
by ragnot 3y ago
This paper will help a lot: https://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf https://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf
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
- john_fushi 3y agoThanks for the explanation! 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.