Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The rules for C and Java are different. In Java, it's guaranteed that the assignments in the constructor to fields marked as final is visible to other threads before the newly constructed object is (unless you stash a reference to it before returning to the constructor), but C has no such guarantee, so in C you have to put the memory barriers yourself.


Yes, what Java gives you for immutable objects is a guarantee of safe publication. In both languages, once you have the object published, you can freely share it between threads.




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

Search: