我正在写消息队列
if (msgsnd(q, &msg, sizeof(message), slaves_list[to]) == -1)
阅读
if (msgrcv(q, &msg, sizeof(message), id, 0) == -1)
但是如果这个队列是空的呢?如何检查?如果没有我想在循环中执行下一条指令
最佳答案
使用IPC_NOWAIT
。来自documentation :
If
(msgflg & IPC_NOWAIT)
is non-zero, the calling thread will return immediately with a return value of-1
and errno set to[ENOMSG]
.
关于c - 从消息队列中读取(如果为空则非阻塞),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13974512/