如何将valgrind与无锁数据结构一起使用



我正在liblfds库中试用无锁结构(http://www.liblfds.org/)着眼于在工具链中使用它们,该工具链还包含用于各种错误检查的valgrind,这给我带来了一些麻烦。我构建了该库的调试版本,并用它编译了以下程序:

#include <liblfds.h>
#include <stdio.h>
#include <pthread.h>
static void *
handler(void *arg)
{
  struct queue_state *queue = (struct queue_state *)arg;
  const char *message;
  int result = queue_dequeue(queue, (void **)&message);
  assert(0 != result);
  printf("%sn", message);
  return NULL;
}
int
main(int argc, const char *argv[])
{
  struct queue_state *queue;
  int result = queue_new(&queue, 1);
  assert(0 != result);
  pthread_t thread;
  result = pthread_create(&thread, NULL, handler, queue);
  assert(0 == result);
  result = queue_guaranteed_enqueue(queue, (void *)"Hello lock free queue!");
  assert(0 != result);
  result = pthread_join(thread, NULL);
  assert(0 == result);
}

这个程序从命令行执行时运行良好,但在valgrind下运行时会出现问题。memcheck报告依赖于未初始化值的跳转,并且当子线程尝试将值出列时,DRD和helgrind都会导致程序失败(queue_dequeue返回0,触发断言)。我可以处理内存检查报告,但DRD和helgrind崩溃是一个阻碍。

我确信,要想实现这一点,需要插入一些客户端请求宏,但线程错误检查器宏的文档面向互斥结构,而不是pthread提供的互斥结构,以及来自自定义分配器的内存处理。在我深入研究如何/是否能做到这一点之前,我希望能有一个指针指向解决过(也许解决了)这个问题的人提供的信息。

您可以随时在网站论坛上询问图书馆作者:-)

据我所知,valgrind在没有任何警告的情况下通过了第6版,所以你的经历是出乎意料的。

在liblfds dot org.上给我发一封电子邮件-admim

相关内容

最新更新