http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46455

--- Comment #9 from Zouzou <internet at 123gen dot com> 2010-11-15 13:46:33 UTC 
---
(In reply to comment #7)
> Could you try this, which is a simplified version of the shared_ptr 
> refcounting
> code and should have the same behaviour:
> #include <ext/atomicity.h>
> #include <ext/concurrence.h>
> #include <assert.h>
> static int count0 = 0;
> struct X
> {
>     X() : count1(1), count2(1) { ++count0; }
>     ~X() { assert( count1==0 ); assert( count2==0 ); --count0; }
>     void release()
>     {
>         if (__gnu_cxx::__exchange_and_add_dispatch(&count1, -1) == 1)
>         {
>             if (__gnu_cxx::__exchange_and_add_dispatch(&count2, -1) == 1)
>                 delete this;
>         }
>     }
>     __gnu_cxx::__mutex m;
>     _Atomic_word count1;
>     _Atomic_word count2;
> };
> int main()
> {
>     for (int i=0; i<100; ++i)
>     {
>         X* x = new X;
>         x->release();
>     }
>     assert( count0 == 0 );
> }

[i added a Sleep(100) call after x->release(); for easier diagnostics.]

this code produces the same behavior as my test case (increasing number of
semaphores, over 100 after 10 seconds) on both vanilla MinGW and mingw64.

to summarize: my test case (standard shared_ptr creation) worked fine on
mingw64 (which has a __gnu_cxx::__default_lock_policy = 2) but bugged on
vanilla MinGW (which has a __gnu_cxx::__default_lock_policy = 1); but this one
produces the bug in both cases.

Reply via email to