我正在使用 boost message_queue,并在一个 C++ 程序中创建队列并在另一个程序中使用它。
我的问题是,有时第一个程序尚未运行,但第二个程序正在运行。
所以当我启动第一个程序时,我想知道队列是否存在。 我不想使用 message_queue::remove() 因为我不想丢失一些数据。
问题是,我如何知道 message_queue "bla_bla_queue"是否存在?
message_queue q(open_only,"q");
最佳答案
根据doc :
Opens a previously created process shared message queue with name "name". If the queue was not previously created or there are no free resources, throws an error.
因此,如果消息队列不存在,您应该能够捕获异常。
一个simple test_program告诉我,interprocess_exception抛出错误,错误码为7,表示not_found_error
.
关于c++ - 如何检查boost消息队列是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50839639/