-
Notifications
You must be signed in to change notification settings - Fork 84
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
Question: Handlers, volatile and visibility #106
Comments
On a related note, I've found that the delivery order for This means, visibility aside, if anything in |
(Note that |
If you need the The JavaDoc for
|
I'll readily admit I overlooked the documentation. Apologies. It seems like the That said, it feels unnecessary that it work that way. For the moment, we've done exactly that, and implemented our own handling that eliminates this race, to ensure developers writing process handlers in Bitbucket Server observe reliable delivery where Setting that aside, though, my bigger questions remain and are not addressed in the Javadocs: What sort of visibility and "happens-before" guarantees do Thanks for your help! |
I agree re: the README, the example should probably use I would say do not rely on any memory fences that may or may not exist in the library, as it is always possible they may change. I would recommend using something like I agree with the statement:
But perhaps, unlike you, I do not see this as a problem. All other synchronization is up to the user. |
Context:
In the README for this project, there are a couple handler examples that both follow the same pattern:
process
field with theNuProces
passed toonStart
process
inonStdout
When using
NuProcessBuilder.start
, it's guaranteed (as far as I can tell) thatonStart
andonStdout
will be called on different threads. That implies it may be necessary to mark theprocess
field in the handlervolatile
to ensure the value assigned inonStart
is visible ononStdout
. However, none of the examples (or test handlers) do so.Question:
What sorts of visibility assurances come with handlers? What enforces them? The
Process*
types that run the I/O loops for processes utilize variousvolatile
fields, as well as somejava.util.concurrent
types. Are those usages enough to ensure sufficient memory barriers are in place "around" handler callbacks that handlers don't need to usevolatile
explicitly?I'm just trying to get a clear sense of how much the thread mismatch between
onPreStart
/onStart
, which are always called on thestart()
ing thread, and the otheron*
methods, which (aside fromonExit
) are always called on a pump thread, needs to be accounted for by handler implementations.onExit
seems to be somewhat unique in that, at least how I read the code, in certain cases it's possible for it to be called on theonPreStart
/onStart
thread (e.g. if starting a process fails) and in others on the pump thread.The text was updated successfully, but these errors were encountered: