View topic - mq_notify

Page 1 of 1

mq_notify

PostPosted: Thu Jun 09, 2016 2:40 pm
by sheran.vaz
Within a single process, Can mq_notify be used to send notification for Q1(queue) to T1's(thread) C1(channel) and also Q2(queue) to T2's(thread) C2(channel)? (or) is it like a single process can use mq_notify, only for 1 queue at an instant?

Re: mq_notify

PostPosted: Thu Jun 09, 2016 3:05 pm
by nico04
Do you really need mq to communicate inside your process ?
mq is a "heavy" solution. It's usage is more for inter process communication.

Re: mq_notify

PostPosted: Thu Jun 09, 2016 3:12 pm
by sheran.vaz
Good question. The reason Qs were choosen is because the thread which feeds this queue is of higher priority than the reader threads. We do not want the high priority thread to get blocked because the critical section is locked by lower priority thread.

Re: mq_notify

PostPosted: Thu Jun 09, 2016 5:35 pm
by Tim
You should consider using pthread conditional variables within your process.

http://www.qnx.com/developers/docs/6.3. ... _init.html
http://www.qnx.com/developers/docs/6.3. ... _init.html

The idea is you create a regular pthread mutex and then put that into a conditional variable.

The mutex protects access to your queue (a simple C++ list/vector or roll your own etc). The condition variable lets the reader threads sleep until the queue is non-empty at which time they can wake up, get the mutex, pull an entry from the queue to process and then release the mutex.

Tim

Re: mq_notify

PostPosted: Fri Jun 10, 2016 6:20 am
by nico04
On my side, I have written a FIFO (a queue) in C.
I use a mutex to protect access to a circular buffer and a semaphore to represent the amount of valid entries in the FIFO.
Appending an entry in the FIFO adds the entry in the buffer tail and posts to the semaphore.
Getting an entry from the FIFO waits for the semaphore and removes head entry from the buffer.

Re: mq_notify

PostPosted: Fri Jun 10, 2016 6:04 pm
by sheran.vaz
Thanks for the inputs.

The problem was with the sequencing, i hadn't created the connection to receive the first notification.

Agree that Queues are heavier than accessing local circular buffer, which is inside the same process address space.