Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

18
LINES

< > BotCompany Repo | #1009679 // AutoInitVar - thread-safe variable that initializes itself once

JavaX fragment (include)

1  
sclass AutoInitVar<A> extends Var<A> {
2  
  O make;
3  
  bool has;
4  
  Lock lock = lock();
5  
  
6  
  *() {}
7  
  *(O *make) {}
8  
  
9  
  public A get() {
10  
    if (has) ret super.get();
11  
    lock lock;
12  
    if (has) ret super.get();
13  
    set((A) pcallF(make));
14  
    make = null;
15  
    has = true;
16  
    ret super.get();
17  
  }
18  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009679
Snippet name: AutoInitVar - thread-safe variable that initializes itself once
Eternal ID of this version: #1009679/2
Text MD5: 6bb98c46a4ed39f26c2b1d873c6bb9f2
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-29 00:06:14
Source code size: 311 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 552 / 1561
Version history: 1 change(s)
Referenced in: [show references]