Download Jar. Libraryless. Click here for Pure Java version (7260L/50K).
1 | !7 |
2 | |
3 | // apparently this is the correct way to do double-checked locking |
4 | |
5 | sclass A {}
|
6 | |
7 | static volatile A lazy; |
8 | |
9 | static A getA() {
|
10 | A tmp = lazy; /* Minimize slow accesses to `volatile` member. */ |
11 | if (tmp == null) {
|
12 | synchronized (mc()) {
|
13 | tmp = lazy; |
14 | if (tmp == null) |
15 | lazy = tmp = new A; |
16 | } |
17 | } |
18 | ret tmp; |
19 | } |
20 | |
21 | p-exp {
|
22 | print(getA()); |
23 | print(getA()); |
24 | } |
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1029155 |
| Snippet name: | Double Checked Locking Example |
| Eternal ID of this version: | #1029155/2 |
| Text MD5: | bc6879c7074bea57a6e40960c903a8da |
| Transpilation MD5: | 5121d55d5ff9ede9d7edf69bd7edb837 |
| Author: | stefan |
| Category: | javax / html |
| Type: | JavaX source code (desktop) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2020-07-22 02:38:40 |
| Source code size: | 402 bytes / 24 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 497 / 1409 |
| Version history: | 1 change(s) |
| Referenced in: | [show references] |