Mercury Bugs - mercury
View Issue Details
0000416mercuryBugpublic2016-08-31 17:042016-08-31 17:04
Reportermaxime 
Assigned To 
PrioritynormalSeveritycrashReproducibilityalways
StatusnewResolutionopen 
PlatformJava backendOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000416: mutable thread_local java backend missing initialValue()
DescriptionIn the java backend, when compiling a thread_local mutable, mmc generates a static field
static java.lang.ThreadLocal<Type> module__mutable_variable_name_of_mutable = new java.lang.InheritableThreadLocal<Type>();
which is set via set(...) to the initial value into a initialise declaration (static code block).
The issue is that the InheritableThreadLocal MUST override the initialValue() method, returning the initial value.
Why? because in threads may have been created by a container before the static block has executed, leading in the end to a NullPointerException, because a such a thread from a thread-pool is executing code using the mutable, which does not have a parent-child relation with the thread in which the mutable was initialized.
Steps To ReproduceCreate a module with a thread_local mutable, compile to a jar, create a main java, which creates threads before calling anything from the jar, then from multiple threads, use the mutable.

Additional InformationThe generated code should either be
static java.lang.ThreadLocal<Type> module__mutable_variable_name_of_mutable = new java.lang.InheritableThreadLocal<Type>() {
protected java.lang.Integer initialValue() {return <VALUE>;}
};

Or
static java.lang.ThreadLocal<Type> module__mutable_variable_name_of_mutable;
and in the initialization code, instead of doing a set(...), do a
new java.lang.InheritableThreadLocal<Type>() {
protected java.lang.Integer initialValue() {return <VALUE>;}
};
TagsNo tags attached.
Attached Files

There are no notes attached to this issue.

Issue History
2016-08-31 17:04maximeNew Issue