incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Teleman <stefan.tele...@gmail.com>
Subject Re: STDCXX-1056 [was: Re: STDCXX forks]
Date Tue, 18 Sep 2012 17:21:52 GMT
On Tue, Sep 18, 2012 at 12:43 PM, Liviu Nicoara <nikkoara@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.teleman@gmail.com

Mime
View raw message