Skip to content
This repository has been archived by the owner on Sep 17, 2020. It is now read-only.

FP: Useless void method #28

Closed
ben-manes opened this issue Nov 6, 2016 · 1 comment
Closed

FP: Useless void method #28

ben-manes opened this issue Nov 6, 2016 · 1 comment
Labels

Comments

@ben-manes
Copy link

The method SingleConsumerQueue.LinearizableNode.await() seems to do nothing useful.
Analysis discovers that void method SingleConsumerQueue.LinearizableNode.await() has non-trivial body, yet does nothing useful. Probably there's some mistake.

This is a spin loop watching a volatile field. This would be true if the field was non-volatile, as the JVM could optimize it away as dead code. The volatile introduces a load barrier so that the signal is observed.

volatile boolean done;

void await() {
  while (!done) {}
}
@amaembo
Copy link
Owner

amaembo commented Nov 8, 2016

I can exclude volatile read from operations w/o side-effect, but spin-loop is usually a bad practice. There are better concurrency primitives which will not burn your CPU uselessly...

@amaembo amaembo added the bug label Nov 8, 2016
amaembo added a commit that referenced this issue Nov 8, 2016
@amaembo amaembo closed this as completed Nov 8, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants