代码之家  ›  专栏  ›  技术社区  ›  John Perry

赫尔辛基和原子旗

  •  1
  • John Perry  · 技术社区  · 7 年前

    atomic_flag cplusplus.com

    164 errors from 28 contexts (suppressed: 0 from 0)
    

    例如

    ==4868== Possible data race during read of size 1 at 0x605220 by thread #3
    ==4868== Locks held: none
    ==4868==    at 0x401172: test_and_set (atomic_base.h:176)
    ==4868==    by 0x401172: append_number(int) (helgrind_spinlock.cpp:12)
    [output deleted]
    ==4868== This conflicts with a previous write of size 1 by thread #2
    ==4868== Locks held: none
    ==4868==    at 0x4011C9: clear (atomic_base.h:193)
    ==4868==    by 0x4011C9: append_number(int) (helgrind_spinlock.cpp:14)
    [output deleted]
    

    在正确使用 作为一个旋转锁,还是Helgrind给出了一个假阳性?

    1 回复  |  直到 7 年前
        1
  •  4
  •   phd    7 年前

    这些都是假阳性。Helgrind不理解“低级”同步, 它只理解posix同步原语。

    参见用户手册 http://www.valgrind.org/docs/manual/hg-manual.html#hg-manual.effective-use 比如说:

    确保您的应用程序及其使用的所有库都使用 POSIX线程原语。Helgrind需要能看到所有的东西 同步事件。为此,它拦截了许多POSIX pthreads 功能。

    Linux futex系统调用、原子计数器等的组合 抛开Helgrind的内部模型

    因此,等待helgrind理解c++原子标志,您将有 基于原子标志的同步原语。

    推荐文章