[ 
https://issues.apache.org/jira/browse/MATH-1134?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14049121#comment-14049121
 ] 

Gilles commented on MATH-1134:
------------------------------

0) is a bit sad, because it can be thread-safe in an obvious way (all fields 
"final").

Affirming thread-safety with 1) might not be as obvious. If only the "private" 
method that computed the derivatives were "synchronized", there might still be 
race conditions (leading to multiple computations of the same fields). While 
having all accessors synchronized will bring a penalty to applications that 
really make concurrent accesses.

2) is not efficient, always (if derivatives are used).

3) is not efficient, at instantiation.

bq. Gilles suggestion to make 3) itself configurable sort of combines 3) and 0)

Yes, IIUC what you means by "combines".
Users who need the derivatives would have to specifically request that 
derivatives are computed (at instantiation), while the default would leave them 
at "null" (and if called later a NPE will be raised, by the JVM).
\[This is my preferred option. And you didn't rank it ;)\]

Another option might be to deprecate the derivatives code altogether. And 
perhaps move it to a subclass. And reimplement it, using the 
"o.a.c.m.analysis.differentiation.DerivativeStructure".


> unsafe initialization in BicubicSplineInterpolatingFunction
> -----------------------------------------------------------
>
>                 Key: MATH-1134
>                 URL: https://issues.apache.org/jira/browse/MATH-1134
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.3
>            Reporter: Derek Scherger
>            Priority: Minor
>
> The lazy initialization of the internal array of partialDerivatives in 
> BicubicSplineInterpolatingFunction is not thread safe. If multiple threads 
> call any of the partialDerivative functions concurrently one thread may start 
> the initialization and others will see the array is non-null and assume it is 
> fully initialized. If the internal array of partial derivatives was 
> initialized in the constructor this would not be a problem.
> i.e. the following check in partialDerivative(which, x, y)
>         if (partialDerivatives == null) {
>             computePartialDerivatives();
>         }
> will start the initialization. However in computePartialDerivatives()
>         partialDerivatives = new BivariateFunction[5][lastI][lastJ];
> makes it appear to other threads as the the initialization has completed when 
> it may not have.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to