...
This code also violates TSM03-J. Do not publish partially initialized objects.
Compliant Solution (
...
Volatile)
This compliant solution declares the helper
field volatile.
...
Wiki Markup |
---|
*LCK10-EX0:* Use of the noncompliant form of the double-checked locking idiom is permitted for 32-bit primitive values (for example, {{int}} or {{float}}) \[[Pugh 2004|AA. Bibliography#Pugh 04]\], although this usage is discouraged. The noncompliant form establishes the necessary happens-before relationship between threads that see an initialized version of the primitive value. The second happens-before relationship (that for the initialization of the fields of the referent) is moot of no practical value, because unsynchronized reads and writes of primitive values up to 32-bits are guaranteed to be atomic. Consequently, the noncompliant form establishes the only needed happens-before relationship in this case. Note, however, that the noncompliant form fails for {{long}} or {{double}} because unsynchronized reads/ or writes of 64-bit primitives lack a guarantee of atomicity, and consequently require a second happens-before relationship to guarantee that all threads see only fully assigned 64-bit values (See rule [VNA05-J. Ensure atomicity when reading and writing 64-bit values].) |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="46e45a6d5985c131-4047f841-45b646b3-baf29b9a-956b1426b2a83fd3630f7579"><ac:plain-text-body><![CDATA[ | [[API 2006 | AA. Bibliography#API 06]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="2070f40435341aec-2aef2d9b-423a42c7-a38fbd51-c60e0e511229b3b8a9ab02e7"><ac:plain-text-body><![CDATA[ | [[JLS 2005Bloch 2001 | AA. Bibliography#JLS 05Bibliography#Bloch 01]] | §12.4, "Initialization of Classes and Interfaces Item 48: "Synchronize access to shared mutable data" | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="9bf75bcefa6eb4c8-de7678d4-453e4899-898a8115-fcdfa72d6953bcbb386c11e3"><ac:plain-text-body><![CDATA[ | [[Pugh 2004Bloch 2008 | AA. Bibliography#Pugh 04Bibliography#Bloch 08]] |
| Item 71: "Use lazy initialization judiciously"]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8108379c134075e8-0bf532e9-480144f0-884192da-f879d8e4fbf4919204c181e4"><ac:plain-text-body><![CDATA[ | [[Bloch 2001JLS 2005 | AA. Bibliography#Bloch 01Bibliography#JLS 05]] | Item 48: "Synchronize access to shared mutable data §12.4, "Initialization of Classes and Interfaces" | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="bf8c062844a80d6e-ff59a228-4f9349fc-a199adc3-62c71b6c34ef2c779ff08959"><ac:plain-text-body><![CDATA[ | [[Bloch 2008Pugh 2004 | AA. Bibliography#Bloch 08Bibliography#Pugh 04]] |
| Item 71: "Use lazy initialization judiciously"]]></ac:plain-text-body></ac:structured-macro> |
...