Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8755999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:58:03+00:00 2026-06-13T13:58:03+00:00

I thought of trying out thread sanitizer ( http://code.google.com/p/data-race-test/wiki/ThreadSanitizer#Using_ThreadSanitizer ) so I made a

  • 0

I thought of trying out thread sanitizer ( http://code.google.com/p/data-race-test/wiki/ThreadSanitizer#Using_ThreadSanitizer )
so I made a simple program:

#include <thread>
#include <atomic>
#include <vector>
#include <iostream>
#include <algorithm>
#include <mutex>
using namespace std;
int violated=0;
mutex mtx;
void violator()
{
    lock_guard<mutex> lg(mtx);
    violated++;
}
int main()
{
    thread t1(violator);
    t1.join();
    thread t2(violator);
    t2.join();
}

AFAIK program is OK since access to violated is synced with mutex(and like comments say even without that program is race free).
But tsan complains and gives a bunch of warnings:
http://www.filedropper.com/output
So am I using the tool wrong, or is it not really good ?
If important I’m using VS11 Beta.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:58:04+00:00Added an answer on June 13, 2026 at 1:58 pm

    This is normal, ThreadSanitizer does not know how to deal properly with the C++11 threading libraries, it also can’t handle fine-grained synchronization using Interlocked* or std::atomic. Additionally the hybrid mode can produce false positives. You can build a suppression file to ignore races in the standard libraries and other false positives. Using your code on linux x64 and ThreadSanitizer I got 7 false races in the stdlib. After adding a suppression file I was able to ignore these races. Then I removed your lock and moved your t1.join() to after the start of the second thread (so there is a real race.) ThreadSanitizer detects this correctly. Then I added your mutex back in and the race was no longer reported. So it does in fact seem quite useful. Google uses it to find races in their Chrome browser, among many other projects, so it’s quite mature (although building it on my ubuntu 12.10 system was a real pain.)

    For linux my suppression file looks like:

    {
    <std::shared_ptr>
    ThreadSanitizer:Race
    ...
    fun:std::_Sp_counted_base::_M_release
    fun:std::__shared_count::~__shared_count
    fun:std::__shared_ptr::~__shared_ptr
    }
    {
    <std::arena_thread_freeres>
    ThreadSanitizer:Race
    fun:arena_thread_freeres
    fun:__libc_thread_freeres
    fun:start_thread
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to figure this out for hours, so thought I should ask
i just started learning swings. And thought of trying out a simple program, but
I have a question about pthread_kill() behavior. Here's a small code I'm trying out:
I was just starting out on LinqPad and trying some thread snippets in it
I'm trying to work out how to iterate though a returned SimpleXML object. I'm
actually I thought I was trying something really simple. ControllerClassNameHandlerMapping sounded great to produce
I am trying to Emit what I thought would be a simple object array
I am trying to replicate TryParse for generic types and thought that TypeDescriptor might
I'm trying to do something which I thought would be fairly simple. Get IIS
I'm trying to do something that I thought ought to be reasonably simple but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.