|
From: Julian S. <js...@ac...> - 2011-03-13 12:14:52
|
> Sorry, but I disagree - the above code introduces a race condition and
> hence it is incorrect.
Ok -- I'm not sure I'm correct on this either :-) If anything it goes
to show how hard it is to reason about the behaviour of concurrent
programs.
I think it would be useful to separate the question of why a race
is reported in the original version from the question of how to fix
it. So, first of all, do you agree with my analysis of why the
race is reported -- because the atomic load/store is concurrent with
the delete ?
> > U_ANNOTATE_HAPPENS_BEFORE(m_count_ptr);
> > if (--(*m_count_ptr) == 0)
> > {
> > U_ANNOTATE_HAPPENS_AFTER(m_count_ptr);
> > delete m_ptr;
> > m_ptr = NULL;
> > delete m_count_ptr;
> > m_count_ptr = NULL;
> > }
> > }
J
|