2012-08-03 54 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點組織。

相關問題