A possible race condition in Packet::invalidateHeader()

Dear all

While doing the refactoring of this function, the race poped out …. ;-)

if (!x->ref.deref())

delete x;

Now what happens thread T1 has finish checking the above conditional and is then pre empted … T2 runs the the same conditional and deletes x. Thread T1 resumes and deletes x

As we are using thread safe functions to swap ( if I am right ) the pointers, we should consider all races

Adding multi-threading at some later point in the code is very hard …

—- cheers atul

Would you like to post a relpy?


This post starts a thread.
Follow-ups:
Re: A possible race condition in Packet::invalidateHeader()
Hi Atul, Did you verify that a race occurs? I that should not be the case. QBasicAtomic::ref() and QBasicAtomic::deref() are atomic operations. if (!x->ref.deref()) delete x; The implementation of deref() (more...)