Libraryless. Click here for Pure Java version (67L/1K).
1 | sclass AtomicCounter { |
2 | volatile int counter; |
3 | |
4 | // statically get var handles |
5 | private static final VarHandle vhCounter; |
6 | static ctex { |
7 | var l = MethodHandles.lookup(); |
8 | vhCounter = l.findVarHandle(AtomicCounter.class, "counter", int.class); |
9 | } |
10 | |
11 | int incCounter aka inc() { |
12 | ret (int) vhCounter.getAndAdd(this, 1)+1; |
13 | } |
14 | } |
Began life as a copy of #1035570
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): elmgxqgtpvxh, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035581 |
Snippet name: | AtomicCounter |
Eternal ID of this version: | #1035581/4 |
Text MD5: | 5ad88a61b8bf1d5064d05ce8a6382365 |
Transpilation MD5: | 6319db0f46663e9496dd8bbbf677d863 |
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:00:50 |
Source code size: | 354 bytes / 14 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 77 / 126 |
Version history: | 3 change(s) |
Referenced in: | [show references] |