1

I am using msgrcv() to read messages from a queue. There are multiple threads, each handling its own message type from a common queue. Lets say there are 3 threads handling message type A, B and C respectively as below: `

thread1()
{
    msg_t msg;
    while(1)
    {
        msgrcv(qid, msg, sizeof(msg), A, 0)
        .
        .
    }
}
.
.
thread2()
{
    msg_t msg;
    while(1)
    {
        msgrcv(qid, msg, sizeof(msg), B, 0)
        .
        .
    }
}
.
.
thread3()
{
    msg_t msg;
    while(1)
    {
        msgrcv(qid, msg, sizeof(msg), C, 0)
        .
        .
    }
}

`

Now I want a fourth thread that can receive all the messages except these three. Can it be achieved using MSG_EXCEPT flag?

Thanks.

I dont know how to use 'MSG_EXCEPT' flag to exclude multiple message types at once.

1 Answers1

0

Can it be achieved using MSG_EXCEPT flag?

No, it can't. Instead, provided that you can arrange A, B and C to be greater than all other used message types, you can achieve the goal by specifying the negative of a msgtyp less than A, B and C.

Armali
  • 18,255
  • 14
  • 57
  • 171
  • The actual issue I am facing is that I sometimes see a large number of bytes in the queue (checked using **msqid_ds** structure)whenever a message(either A, B, or C) is sent and neither of the three threads fetches the message from the queue. So I am doubting that somehow the message is corrupted and the message type of the new message is different from A, B, and C. All three threads are stuck on msgrcv() function. – Lalit Meena Dec 05 '22 at 04:27
  • The **msqid_ds** logs each time I send a message are as: Number of bytes in queue: 5281 Maximum number of bytes in queue: 16384 Number of msgs in queue: 1 Number of bytes in queue: 10561 Maximum number of bytes in queue: 16384 Number of msgs in queue: 2 – Lalit Meena Dec 05 '22 at 04:35
  • What you write doesn't preclude the option to choose the three highest possible integers for A, B and C and to then receive all other messages with the negative of a _msgtyp_ one less. – Armali Dec 07 '22 at 00:20