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

19
LINES

< > TinyBrain | #1003550 - class Var - thread-safe variable

JavaX fragment (include)

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

download  show line numbers  debug dex   

Travelled to 12 computer(s): cfunsshuasjs, ddnzoavkxhuk, fehiwqupcyrn, gwrvuhgaqvyk, imzmzdywqqli, jtubtzbbkimh, lhdilzshxjzv, lulzaavyztxj, onxytkatvevr, sawdedvomwva, tvejysmllsmz, wtqryiryparv

No comments. add comment

Snippet ID: #1003550
Snippet name: class Var - thread-safe variable
Eternal ID of this version: #1003550/5
Text MD5: 14f26709acf7fb224c7d4c5f3e2e41d6
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-09-13 22:04:06
Source code size: 426 bytes / 19 lines
Pitched / IR pitched: No / No
Views / Downloads: 131 / 8526
Version history: 4 change(s)
Referenced in: [show]