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

18
LINES

< > BotCompany Repo | #1019343 // class LockedVar - thread-safe variable (same as Var), but using a ReentrantLock

JavaX fragment (include)

1  
static class LockedVar<A> implements IVar<A> {
2  
  A v; // you can access this directly if you use one thread
3  
  transient Lock lock = lock();
4  
  
5  
  *() {}
6  
  *(A *v) {}
7  
  
8  
  public void set(A a) {
9  
    lock lock;
10  
    v = a;
11  
  }
12  
  
13  
  public A get() { lock lock; ret v; }
14  
  public bool has() { lock lock; ret v != null; }
15  
  public void clear() { lock lock; v = null; }
16  
  
17  
  toString { ret str(get()); }
18  
}

Author comment

Began life as a copy of #1003550

download  show line numbers  debug dex  old transpilations   

Travelled to 12 computer(s): bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019343
Snippet name: class LockedVar - thread-safe variable (same as Var), but using a ReentrantLock
Eternal ID of this version: #1019343/2
Text MD5: c9a0a7063eaeeeb2855c791aaa01819f
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-11-03 12:59:29
Source code size: 414 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 237 / 772
Version history: 1 change(s)
Referenced in: [show references]