【问题标题】:how to spsc_queue.pop() this struct?如何 spsc_queue.pop() 这个结构?
【发布时间】:2013-09-14 00:35:47
【问题描述】:

我正在尝试spsc_queue.pop() 这个struct

enum action_type {
    SUBSCRIBE,
    UNSUBSCRIBE,
    MESSAGE
};

struct action {
    action() = default ;
    action(action_type t, connection_hdl h) : type(t), hdl(h) {}
    action(action_type t, server::message_ptr m) : type(t), msg(m) {}

    action_type type;
    websocketpp::connection_hdl hdl;
    server::message_ptr msg;
};

action a;
while(m_actions.pop(a)){
    ...

但每当我测试时

std::cout << "'" << a.type << "'" << std::endl;

'0' 被写入终端,但它应该只是action_type 的值之一。我读过struct 的默认值是0,但为什么spsc_queue.pop() 不能设置a

(boost::lockfree::spsc_queue)

【问题讨论】:

    标签: c++ boost struct queue lock-free


    【解决方案1】:

    SUBSCRIBE 的值 0。如果你想给 SUBSCRIBE 一个不同的值,你可以初始化枚举器,例如,使用 1:

    enum action_type {
        SUBSCRIBE = 1,
        UNSUBSCRIBE,
        MESSAGE
    };
    

    其他枚举器将获得各自的下一个整数值。

    【讨论】:

      猜你喜欢
      • 2022-12-05
      • 2012-08-25
      • 2021-09-23
      • 1970-01-01
      • 1970-01-01
      • 2016-01-22
      • 2012-04-13
      • 2011-12-17
      • 1970-01-01
      相关资源
      最近更新 更多