【发布时间】:2014-09-29 04:25:05
【问题描述】:
我为 ARM (arm-poky-linux) 交叉编译了 zmq 和 czmq 以构建一个 PUB-SUB 消息路由器。在程序中,我使用zthread_fork() 分叉一个附加线程并通过管道进行对话。当我在分叉后从 main 执行 zstr_rcv() 时,出现分段错误。这段代码在我的带有 GCC 的 Ubuntu 盒子中运行良好。我在这里做错了什么?还是 ARM 兼容性问题?
下面是一个简单的代码sn-p。
// 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;
}
【问题讨论】:
标签: c linux segmentation-fault pipe zeromq