My hypothesis is that this read is not atomic, the high bits are read, then the timer rolls over to a new high bit, the low bits have gone from max to min value when they roll over, and now the low bits are read.
Before the call to getUsed the timer may have been
0xFAFF
Now it's
0xFB00
The JavaScript code reads
0xFA00
(Numbers not to scale)
|
return isolate.cpuTime[0] * 1e3 + isolate.cpuTime[1] / 1e6; |
I believe if cpuTime is copied to a local value first, and then destructed [0], [1]. Time will no longer go backwards and getUsed will never be negative
Cheers.
My hypothesis is that this read is not atomic, the high bits are read, then the timer rolls over to a new high bit, the low bits have gone from max to min value when they roll over, and now the low bits are read.
Before the call to getUsed the timer may have been
0xFAFF
Now it's
0xFB00
The JavaScript code reads
0xFA00
(Numbers not to scale)
driver/lib/runtime/runtime.js
Line 26 in e691bd3
I believe if cpuTime is copied to a local value first, and then destructed [0], [1]. Time will no longer go backwards and getUsed will never be negative
Cheers.