Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential multi-threading issue in tests with timeouts #388

Closed
PhillHenry opened this issue Feb 21, 2012 · 5 comments
Closed

Potential multi-threading issue in tests with timeouts #388

PhillHenry opened this issue Feb 21, 2012 · 5 comments

Comments

@PhillHenry
Copy link

FailOnTimeout.StatementThread.fFinished should be volatile since at least 2 threads access it: the main thread and StatementThread (which is started by main).

This is "to ensure that updates to a variable are propagated predictably to other threads" (Java Concurrency in Practice, 3.1.4, Joshua Bloch).

@Tibor17
Copy link
Contributor

Tibor17 commented Feb 22, 2012

+1
a god point

I recommend to use volatile on fExceptionThrownByOriginalStatement as well .

I would recommend you to redesign the constructor in order to initializing the volatile variables before final in the constructor to make sure that all are properly initialized before constructor freeze. The volatile needs write a dummy operation first even if false or null by the spec:

private final Statement fStatement; private volatile boolean fFinished; private volatile Throwable fExceptionThrownByOriginalStatement;

public StatementThread(Statement statement) {
fExceptionThrownByOriginalStatement= null;
fFinished= false;
fStatement= statement;
}

@dsaff
Copy link
Member

dsaff commented Oct 10, 2013

This is an old issue, but may be relatively easy to fix for someone looking for a chance to contribute.

@codingricky
Copy link

@dsaff is this still an issue as FailOnTimeout has variables that are final now so therefore threadsafe.

Thanks.

@kcooney
Copy link
Member

kcooney commented Nov 3, 2013

@codingricky I think this issue was fixed, but the recent changes to FailOnTimeout may have made it not thread-safe since fThreadGroup is neither final nor volatile. I'll comment on pull request #742

@kcooney
Copy link
Member

kcooney commented Jan 29, 2014

The remaining issues were fixed in #765

@kcooney kcooney closed this as completed Jan 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants