Yes I saw those but those didn't do the trick :( or my understanding of how to use these macros is wropng. Maybe I should have left that code in the example ...
I tried: void releaseRef() { ANNOTATE_HAPPENS_BEFORE(&m_nRefCnt); int nRefCnt = __sync_add_and_fetch(&m_nRefCnt, -1); if (nRefCnt == 0) { ANNOTATE_HAPPENS_AFTER(&m_nRefCnt); delete this; } } I did get the race condition suppressed in some cases by using VALGRIND_HG_DISABLE_CHECKING / VALGRIND_HG_ENABLE_CHECKING The problem there is that I do not know the sizeof() the instantiated object the smart-pointer refers to. Aka if the interitance hierarchy is C isa B isa A and I have a smartpointer to B then I do not now that the actual object isa C. I need to know it isa C because that changes the location of where the vtable-pointer of A is stored. This is especially the case when I have multiple inheritance that all share the same base. I think the problem is not with the refcounting, but with the virtual inheritance. Or, formulated as question, what is the difference between the generated code with virtual and non-virtual inheritance, and how does that explain the race condition? I made an assembly-dump of both the compilations to see whether those could support my theory of stuff happening after the releaseRef call. I have an almost negligible knowledge of assembly, but I think that the generated assembly does not show any instructions after the call to releaseRef, but just some more instructions before the call. At the moment I'm not able to post these, but will do if desired. You can generated them yourselfs using the -S flag, something like: g++ -g -DINHERIT="public" -S refcnttst.cc -o refcnttst.s g++ -g -DINHERIT="virtual public" -S refcnttst.cc -o refcnttst-virt.s regards, Joris CONFIDENTIALITY: This e-mail and any attachments are confidential and may be privileged. If you are not a named recipient, please notify the sender immediately and do not disclose the contents to another person, use it for any purpose or store or copy the information in any medium. ------------------------------------------------------------------------------ Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox _______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users