// 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) {} }
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: | 112 / 122 |
Referenced in: | [show references] |