Jump to content

Single Element Queue vs Notifier?


Recommended Posts

They are not the same. A single element queue can be used as a mutex in a by reference style of code. (dequeue locks, enqueue unlocks.) Using a notifier would not allow you to mutex correctly since you cannot wait on notification and cancel it at the same time. You would be required to test that the waited on notificaiton message was identical to the canceled notfication and internally include a modification metric to ensure that you have the correct data in instances where actual data does not change, and retry if you didn' t get the reference (practically speaking I wouldn't even try.)

a notifier would behave the same as an SEQ if you ONLY used the lossy enqueue and preview queue funtions. I'm not sure which one would perform better.

the best performer in this type of by reference structure is the DVR (data value reference)

~Jon

Link to comment

The basic difference of course is that a Notifier is a broadcast mechanism. If you have ten threads waiting on (listening to) the queue, and enqueue an item, then only one will stop waiting. I think it will be the one that started waiting first but I don't know whether that is guaranteed.

If you have ten or ten thousand threads waiting on a notifier, they will all stop waiting and take the update.

With a single element queue, you can't put any more into the queue until the first item is taken out, but with a notifier, you can put as many in as you want, and if the receiving thread or threads don't finish looping in time, they can miss notifications. There is no way for the sender to know if any or all of the recipients have received a particular notification.

Edited by jdunham
  • Like 2
Link to comment

I assume the queue might be better in performance.

More use cases (SEQ, producer-consumer) -> NI put more manpower behind the optimization code -> better performance.

I think 8.5 it was a big marketing about Qs and multicore performance, they never adressed notifiers.

But might be completely missleading, as a notifier only needs 1 piece (the current piece) of data while a queue might queue up (as the name suggests), so those optimizations would be unneccesary for a notifier.

Felix

  • Like 1
Link to comment

I've never seen a use of Notifiers where you couldn't have done it with a Queue. That being said, I like to use Notifiers to send status messages to a tiny parallel loop that sits there un-spinning and patient - waiting for the Notifier to be updated. Then again, you can do that with a Queue too, but why? A "real" SEQ is bulky to set up and use compared to the Notifier.

Link to comment

I've never seen a use of Notifiers where you couldn't have done it with a Queue.

If you have 100 listeners, you would need 100 queues to send the same message to all of them simultaneously. It's much easier with a single notifier. Our software detects events which must be handled by a variety of subsystems all able to run in parallel, and a notifier makes short work of it.

Link to comment

The real cool feature of Single Element Queues is that you can use them as a kind of global variable!

It comes with an integrated semaphore mechanism which helps prevent race conditions (in fact it's the other way round: take a look at LV's semaphore VIs and you will see that they are using Qs internally).

And it can help you to minimize data copies!

Imagine you have an array of one million double value inside an SEQ and you want to read one element from it.

Using the standard dequeue-enqueue mechanism will only make a copy of the extracted element, not of the complete array, since the array buffer can be reused.

Reusing the buffer is only possible in Qs, not in notifiers, since in a notifier the data has to stay inside it in case another process wants to read it afterwards.

Of course the same is true for "Preview Queue Element", so you should not use this if you only want to read a part of the data inside the SEQ.

post-7932-0-54270900-1314089129.png

Link to comment

The real cool feature of Single Element Queues is that you can use them as a kind of global variable!

It comes with an integrated semaphore mechanism which helps prevent race conditions (in fact it's the other way round: take a look at LV's semaphore VIs and you will see that they are using Qs internally).

And it can help you to minimize data copies!

Imagine you have an array of one million double value inside an SEQ and you want to read one element from it.

Using the standard dequeue-enqueue mechanism will only make a copy of the extracted element, not of the complete array, since the array buffer can be reused.

Reusing the buffer is only possible in Qs, not in notifiers, since in a notifier the data has to stay inside it in case another process wants to read it afterwards.

Of course the same is true for "Preview Queue Element", so you should not use this if you only want to read a part of the data inside the SEQ.

Wouldn't DVR's and IPE be better suited to this task (i.e. easier).

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.