Analyzers
Talk to fellow users of Intel Analyzer tools (Intel VTune™ Profiler, Intel Advisor)
5121 Discussions

Trouble using Intel Inspector. Lots of false positive.

Moszkowicz__Uri
Beginner
538 Views

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::parallel_for(
      tbb::blocked_range<SInt32>(0, 1000000),
      [&](tbb::blocked_range<SInt32>& br) {
        randMutex.lock();
        SInt32 randSeed = seedRng.RandNum();
        SInt32 sleepTime = randSeed % 3;

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

        sleep(sleepTime);

        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");
          }
        }

        randMutex.lock();
        activeThreads.RemoveInt(threadId);
        randMutex.unlock();
      });
    printf("Finished with %d threads (max %d)\n", nextThreadId, maxNumThreads);
    exit(0);

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.

0 Kudos
0 Replies
Reply