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)

static class LockedVar<A> implements IVar<A> {
  A v; // you can access this directly if you use one thread
  transient Lock lock = lock();
  
  *() {}
  *(A *v) {}
  
  public void set(A a) {
    lock lock;
    v = a;
  }
  
  public A get() { lock lock; ret v; }
  public bool has() { lock lock; ret v != null; }
  public void clear() { lock lock; v = null; }
  
  toString { ret str(get()); }
}

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: 304 / 841
Version history: 1 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)