【问题标题】:ARM cross compiled ZeroMQ zstr_rcv() gives segmentation faultARM 交叉编译 ZeroMQ zstr_rcv() 给出分段错误
【发布时间】:2014-09-29 04:25:05
【问题描述】:

我为 ARM (arm-poky-linux) 交叉编译了 zmqczmq 以构建一个 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


    【解决方案1】:

    来自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 桌面上摆脱了一个不良行为。尝试建议的释放方法,看看是否效果更好

    【讨论】:

    • 感谢您的快速回复。是的,我的错在那里,但这不是原因。我将其更改为使用zstr_free,但仍然存在分段错误。
    • 根据我在下面的回答,这是我最后的脑放屁。很抱歉给您带来麻烦。
    【解决方案2】:

    这只是库版本不匹配的情况。我没有使用 czmq 所需的 libzmq.so.3,而是使用了 libzmq.so.4。一旦使用了正确的版本,一切都很好。

    在一个更明亮的音符上,希望其他人能从中吸取教训。为造成的混乱道歉。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-13
      • 2014-01-18
      • 1970-01-01
      • 1970-01-01
      • 2020-12-15
      • 2014-06-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多