On Fri, Jun 10, 2016 at 06:49:18AM +0200, Ivo Raisr wrote: >> How can I annotate source code (see below) to stop valgrind's DRD >> tool complain about data race?
> You need to help DRD in such cases because as you said you are not using > common synchronization primitives. The question is also why? This is just example, how to reproduce DRD warnings. Actually I have much more complicated code. I am trying to use valgrind to find bugs on relatively large project, and I have no idea how to avoid warnings in this case, so I asking about it in mailing list. > I was not able to discern your intention but it seems to me you are > introducing a barrier or a producer-consumer queue. Loop (while(n!=0)...) exists only in example. In real code where is no loops, and should be no delays. Object exists or not (it may be deleted, but it is protected against this with mutex holding in object itself). Initially object not exists (pointer is NULL) and all operations with it should return error. Later object is created, after that pointer is swapped. Now any other threads may use the object (again, object protected from data races with mutex in object). At some point in time object may be destroyed and pointer will be set to zero. The problem is, that valgrind not understood, that after the moment, when pointer is swapped (from NULL to real value), the thread that creates the object not touches object anymore. Valgrind should split its "segment" in moment, when pointer is swapped. But I don't know how to annotate code for that. > There are efficient POSIX synchronization primitives for these tasks > which DRD supports natively. This code uses lockless algorithm (based on possibility to swap pointers atomically), and I didn't want neither change it, nor use algorithms that involve mutexes, conditional variables, etc (because this leads to blocking, because synchronization primitive should be correctly initialized and this leads to initialization order problem in C++ program, because this is "production quality" code and I don't want to change it at all, and much more...) > Otherwise use DRD client requests [1] to annotate your intent. Yes, but I now understood, how should I annotate it. ------------------------------------------------------------------------------ What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic patterns at an interface-level. Reveals which users, apps, and protocols are consuming the most bandwidth. Provides multi-vendor support for NetFlow, J-Flow, sFlow and other flows. Make informed decisions using capacity planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e _______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users