我交叉編譯zmq
和czmq
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;
}
感謝您的快速響應。是的,我的不好,但這不是原因。我改變它使用'zstr_free',但仍然存在分段錯誤。 – fortytwo 2014-09-29 04:42:05
根據我的回答,這是我最後的一個大腦放屁。抱歉,添麻煩了。 – fortytwo 2014-09-29 07:20:04