Skip to content

Conversation

@maxcai314
Copy link

NanoHTTPD.java's start(final int timeout, boolean daemon) method uses inter-thread communication to signal the status of the daemon thread. Section 17.3 of the Java Lang Specification states that Thread.sleep has no synchronization semantics, so the compiler does not have to reload values cached in registers after a call to Thread.sleep. This means that the while loop in start() might never terminate, even if the other thread changed the status.

Changing the variables to volatile would require Java to reload the values after each cycle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant