Hacker News new | past | comments | ask | show | jobs | submit login

I think you're right, if access to shared is not in any way synchronized. But the correct way to handle this, at least in this case, is to mark shared as volatile, which guarantees thread B will only ever read null or a fully constructed Foo from shared. This has been the case since Java 5, released 20 years ago, thanks to JSR-133.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: