commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (MATH-899) A random crash of MersenneTwister random generator
Date Sun, 18 Nov 2012 19:38:58 GMT

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

Phil Steitz commented on MATH-899:
----------------------------------

I think the reason that the unit test does not work is that Junit does not actually see the
exception.  The Executor will not propagate it.  Changing the body of the core method (and
other sigs, etc) to the following, I can get consistent failures when I execute with -Dtest=SynchronizedRandomGenratorTest

{code}
final RandomGenerator rng = new MersenneTwister();
final RandomGenerator wrapper = sync ? new SynchronizedRandomGenerator(rng) : rng;
final AtomicBoolean failed = new AtomicBoolean(false);
final ExecutorService exec = Executors.newFixedThreadPool(numThreads);
for (int i = 0; i < numGenerators; i++) {
    exec.execute(new Runnable() {
        public void run() {
            for (int j = 0; j < numSamples; j++) {
                try {
                    wrapper.nextGaussian();   
                } catch (ArrayIndexOutOfBoundsException ex) {
                    failed.getAndSet(true);
                    break;
                }
             }
         }
         });
        }
        exec.shutdown();
        exec.awaitTermination(100, TimeUnit.SECONDS);
        Assert.assertTrue(failed.get());
{code}

What I don't understand is why this consistently succeeds when executed as a single test,
but usually fails when executed as part of the full test suite with
{code}
 mvn clean test
{code}

I would say in any case there is no need to add a unit test to show the non-thread-safety
of MersenneTwister or to verify that adding synchronization does what it says it does, i.e.,
I would say go ahead and commit the wrapper with no test class.
                
> A random crash of MersenneTwister random generator
> --------------------------------------------------
>
>                 Key: MATH-899
>                 URL: https://issues.apache.org/jira/browse/MATH-899
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.0
>         Environment: Windows 7, JDK 1.7.05
>            Reporter: Alexander Nozik
>            Priority: Minor
>         Attachments: SynchronizedRandomGenerator.java, SynchronizedRandomGeneratorTest.java
>
>
> There is a very small probability that MersenneTwister generator gives a following error:

> java.lang.ArrayIndexOutOfBoundsException: 624
> in MersenneTwister.java line 253
> The error is completely random and its probability is about 1e-8.
> UPD: The problem most probably arises only in multy-thread mode.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message