0

我正在 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("%s\n", 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,使断言跳闸)。我可以解决 memcheck 报告,但 DRD 和 helgrind 崩溃是一个阻碍。

我确信要使这项工作正常工作将需要我插入一些客户端请求宏,但是线程错误检查器宏的文档面向互斥结构,而不是 pthread 提供的互斥结构以及来自自定义分配器的内存处理。在我深入研究 valgrind 的核心以弄清楚如何/是否可以使其工作之前,我希望能获得一个由从事过(并可能解决)这个问题的人提供的信息的指针。

4

1 回答 1

0

You could always ask the library author on the site forum :-)

Last I knew, valgrind passed release 6 with no warnings, so your experience is unexpected.

Drop me an email - admim at liblfds dot org.

于 2012-08-13T23:42:31.843 回答