2014-09-29 60 views
0

我交叉編譯zmqczmq ARM(arm-poky-linux)構建PUB-SUB消息路由器。在這個程序中,我使用zthread_fork()分叉了一個附加的線程,並通過管道進行交談。當我在分叉後從主體做zstr_rcv()時,我得到了分段錯誤。這段代碼在我的Ubuntu中使用GCC工作得很好。我在這裏做錯了什麼?還是ARM兼容性問題?ARM交叉編譯的ZeroMQ zstr_rcv()給出了分段錯誤

下面是一個簡單的代碼片段。

// listener thread function. 
static void listener_thread (void *args, zctx_t *ctx, void *pipe) 
{ 
    // Send sync message to main(). 
    zstr_send (pipe, "READY"); 

    // Do work. 
    while (1) 
    { 
     sleep (1); 
    } 
} 


// main() forks the listener thread and waits for the sync message from the listener with zstr_rcv(). 
int main (int argc, char **argv) 
{ 
    // Create a ZeroMQ context. 
    zctx_t *context = zctx_new(); 
    assert (context); 

    // Deploy the listner. 
    void *listener = zthread_fork (context, listener_thread, NULL); 
    assert (listener); 

    // Wait for the sync signal. 
    char *string = zstr_recv (listener); 
    zstr_free (&string); 

    // Do stuff here. 
    while (1) 
    { 
     sleep (1); 
    } 

    return 0; 
} 

回答

0

the manual

// Receive C string from socket. Caller must free returned string using 
// zstr_free(). Returns NULL if the context is being terminated or the 
// process was interrupted. 
CZMQ_EXPORT char * 
    zstr_recv (void *source); 

注意的建議是如何使用zstr_free()而不是free()。運氣好的話,您可能會在Ubuntu桌面上看到一個不好的行爲。嘗試建議的釋放方法,看看這是否更好

+0

感謝您的快速響應。是的,我的不好,但這不是原因。我改變它使用'zstr_free',但仍然存在分段錯誤。 – fortytwo 2014-09-29 04:42:05

+0

根據我的回答,這是我最後的一個大腦放屁。抱歉,添麻煩了。 – fortytwo 2014-09-29 07:20:04

0

這只是一個不匹配的庫版本的情況。我沒有使用czmq所需的libzmq.so.3,而是使用了libzmq.so.4。一旦正確的版本被使用,一切都很好。

請注意,希望其他人能從中學習。爲造成混亂而道歉。