On Tue, Sep 18, 2012 at 12:43 PM, Liviu Nicoara <nikko...@hates.ms> wrote:

> I am attaching a test program which, while 100% MT-safe, is flagged by
> the Solaris thread analyzer.

The program as written is not thread safe. It is reading the value of
the counter variable and performing a zero comparison outside of a
mutex lock:

for (size_t i = 0; i < nloops; ++i) {
        if (counter == 0) {  // <----------- !!!!
            pthread_mutex_lock (&lock);
            if (counter == 0)
                ++counter;
            pthread_mutex_unlock (&lock);
        }
        else {
            // counter value is safe to use here
        }
    }




-- 
Stefan Teleman
KDE e.V.
stefan.tele...@gmail.com

Reply via email to