ask:
Hello author, see the Visibility section, should the toCancel variable defined here be of static type to be effective?
answer:
The variable toCancel needs to be modified with volatile to achieve the expected effect. In Chapter 2, we did not use volatile modification to show the visibility problem. Chapter 3 explains why in detail.