Trouble using Intel Inspector. Lots of false positive.

Trouble using Intel Inspector. Lots of false positive.

I've got a small unit test using Intel TBB:

    SInt32 nextThreadId = 0;
    SInt32 maxNumThreads = 0;
    HashSet activeThreads;

    Random seedRng;
    tbb::spin_mutex randMutex;
      tbb::blocked_range<SInt32>(0, 1000000),
      [&](tbb::blocked_range<SInt32>& br) {
        SInt32 randSeed = seedRng.RandNum();
        SInt32 sleepTime = randSeed % 3;

        SInt32 threadId = nextThreadId;
        printf("Starting thread %d\n", threadId);
        maxNumThreads = (activeThreads.Num() > maxNumThreads) ? activeThreads.Num() : maxNumThreads;


        HashTable hashTable;
        Random random(randSeed);
        for (SInt32 i = br.begin(); i < br.end(); i++)
          SInt32 randNum1 = random.RandNum();
          SInt32 randNum2 = random.RandNum();
          if (!hashTable.Contains(randNum1))
            hashTable.AtPutInt(randNum1, randNum2);

        for (HashIter i(&hashTable); !i.End(); i.Next())
          SInt32 randNum1 = i.GetKeyInt();
          SInt32 randNum2 = i.GetValueInt();
          if (randNum1 == randNum2)
            printf("Impossible happened\n");

    printf("Finished with %d threads (max %d)\n", nextThreadId, maxNumThreads);

The variables randSeed, sleepTime, nextThreadId, maxNumThreads, and activeThreads are all in the critical section and protected by a mutex called randMutex. The programs runs fine on the command line but Intel Inspector reports 42 problems, all data races. Here's the first one

Read: SInt32 threadId = nextThreadId;


Write: nextThreadId++;

Both of these accesses are protected by the spin_mutex. Any idea why it's being reported?

The rest seem to be in other parts of my application that aren't multi-threaded or even executed. My application uses TCmalloc for memory allocation and some of the errors are coming from it.

1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.