ccia_code_samples
ccia_code_samples copied to clipboard
Listing 7.12 - Undefined behaviour
Please consider modifying the implicit-boolean ptr
check at line 34 to ptr->next.ptr
.
https://github.com/anthonywilliams/ccia_code_samples/blob/6e7ae1d66dbd2e8f1ad18a5cf5c6d25a37b92388/listings/listing_7.12.cpp#L34 https://github.com/anthonywilliams/ccia_code_samples/blob/16d50777974df5e8d5c94ba23f914726f06fe36e/listings/listing_7.12.cpp#L34
Even if the stack is empty while calling the destructor, ptr
is a valid pointer from the moment we call head.load()
- this leads to undefined behaviour inside one of the atomic fetch operations.
Whilst this has been a useful exercise in debugging, please also consider uploading fully-functioning code as a means of verifying that the code published actually functions as intended.
I have attached an example here for anyone coming up against similar issues.