www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14025] New: unittests for memoize fail intermittently

https://issues.dlang.org/show_bug.cgi?id=14025

          Issue ID: 14025
           Summary: unittests for memoize fail intermittently
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: r.sagitario gmx.de

The phobos unittest for memoize fails rather often, lately.

core.exception.AssertError std\functional.d(1092): unittest failure

It seems there's some issue with the initialization check in memoize:

        immutable idx1 = hash % maxSize;
        if (!bts(initialized.ptr, idx1))
            return emplace(&memo[idx1], args, fun(args)).res;
        else if (memo[idx1].args == args)
            return memo[idx1].res;

If the same hash happens to be used as one up the recursion chain, initialized
is already set, but arguments in memo[idx1].args are still garbage from the
GC.malloc call. If they happen to be identical to the current arguments, an
uninitialized result is returned.

It's mostly on Win64, but I've seen it on Win32, too.

--
Jan 22 2015