1 | // assumes that each set function is called exactly once |
2 | // (but it doesn't matter which thread you call each of them from.) |
3 | sclass LongPairCollector > AtomicCounter { |
4 | volatile long a; |
5 | volatile long b; |
6 | |
7 | void setA(long a) { this.a = a; itemReceived(); } |
8 | void setB(long b) { this.b = b; itemReceived(); } |
9 | |
10 | LongConsumer setA aka setterForA() { ret a -> setA(a); } |
11 | LongConsumer setB aka setterForB() { ret b -> setB(b); } |
12 | |
13 | void itemReceived { |
14 | if (incCounter() == 2) |
15 | complete(a, b); |
16 | } |
17 | |
18 | // can override or swap |
19 | swappable void complete(long a, long b) {} |
20 | } |
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: | 114 / 125 |
Referenced in: | [show references] |