Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading from message queue (non-blocking if empty)

I'm writing to message queue

if (msgsnd(q, &msg, sizeof(message), slaves_list[to]) == -1)

and reading

if (msgrcv(q, &msg, sizeof(message), id, 0) == -1)

but what if this queue is empty? How to check that? If there is nothing I want execute next instruction in the loop

like image 807
OnTheFly Avatar asked Feb 19 '23 03:02

OnTheFly


1 Answers

Use IPC_NOWAIT. From the 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].

like image 135
NPE Avatar answered Feb 27 '23 10:02

NPE