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

20
LINES

< > BotCompany Repo | #1035582 // LongPairCollector (backup) - concurrent collector for 2 longs with overridable & swappable complete() function

JavaX fragment (include)

// assumes that each set function is called exactly once
// (but it doesn't matter which thread you call each of them from.)
sclass LongPairCollector > AtomicCounter {
  volatile long a;
  volatile long b;

  void setA(long a) { this.a = a; itemReceived(); }
  void setB(long b) { this.b = b; itemReceived(); }
  
  LongConsumer setA aka setterForA() { ret a -> setA(a); }
  LongConsumer setB aka setterForB() { ret b -> setB(b); }
  
  void itemReceived {
    if (incCounter() == 2)
      complete(a, b);
  }
  
  // can override or swap
  swappable void complete(long a, long b) {}
}

Author comment

Began life as a copy of #1035570

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035582
Snippet name: LongPairCollector (backup) - concurrent collector for 2 longs with overridable & swappable complete() function
Eternal ID of this version: #1035582/1
Text MD5: 8bbdc860f7ee82807886a904a6781898
Author: stefan
Category: javax / parallelism
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-06-19 04:20:34
Source code size: 604 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 6 / 11
Referenced in: [show references]