2012-08-03 22 views
0

我正在试验liblfds库(http://www.liblfds.org/)中的无锁结构,着眼于在工具链中使用它们,该工具链还包含用于各种错误检查的valgrind,这会导致我一些麻烦。我建库的调试版本,并用它来编译下面的程序:在命令行中执行时如何将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的胆量之前弄清楚这个问题的人(或者解决了这个问题),然后找出如何做到这一点。

+0

线程正在启​​动并运行queue_dequeue()*之前*您排队元素; queue_dequeue()不会阻塞。这应该没问题 - dequeue应该返回NULL - 但是printf()不会很高兴。 – 2012-08-13 23:44:21

回答

0

你总是可以问库的作者在网站论坛:-)

最后我知道,Valgrind的通过发行6没有警告,让您体验意想不到的。

给我发电子邮件 - admim在liblfds点组织。

相关问题