From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Are Queues thread safe

Solved!
Go to solution

Hi all,

 

Are Queues thread safe i.e. are enqueue, dequeue etc atomic?

 

I'm looking to use Queues to transfer object states between concurrent loops, but am concerned whether I need to protect access via a semaphore.

 

Thanks

 

Phill

0 Kudos
Message 1 of 9
(4,319 Views)
Solution
Accepted by topic author tadders
Yes.  Queue operations are atomic.  It's safe to assume everything in LabVIEW is thread safe unless specifically noted otherwise, since it has always been a language designed for parallel operation.
0 Kudos
Message 2 of 9
(4,317 Views)
To the best of my knowledge they are thread safe.


Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 3 of 9
(4,316 Views)

All operation that are not thread-safe will run in the UI thread. To the best of my knowlege, this is mostly

 

property nodes

Open VI

VI Serve Call by reference (will not bet on this one)

dll calls if not set as thread-safe...

 

AND the Open Application Ref (according to the bug I just chased down that is crashing LV 2009 under Windows 7 Smiley Wink )

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 9
(4,309 Views)

Thanks very much for your input

 

Phill

 

0 Kudos
Message 5 of 9
(4,284 Views)

Hi all,

 

I've been discussing transfering the state of an object between concurrent loops here and was hoping to use a single element queue.

 

I'm still a little worried about a context switch while I'm updating the status of the object in the area highlighted.

 

Would I still need a semaphore lock to ensure the data integrity of the queue between the flush and enqueue in case the data loop sneaks in and tries to read the queue?

 

Concurrency Example.PNG

0 Kudos
Message 6 of 9
(4,276 Views)

You're using the SEQ concept incorrectly. Do a search to see examples of how to use it properly, but basically, you CAN'T use Flush Queue or Preview. You have to use Dequeue because that includes the infinite timeout option, which is critical to the correct operation of a SEQ global.

 

Also, don't use events to pass the data around. If it's contained in your SEQ, keep it there and only there. If you want to make sure the loop has the current data, place the data in the queue before sending the event.


___________________
Try to take over the world!
0 Kudos
Message 7 of 9
(4,262 Views)

Thanks tst,

 

I think you mean something like this, where the data loop dequeues changes to the object state -

 

Is there anyway of using an asynchronous wake up for the timed loop to transfer state?

 

queues.PNG 

 

 

0 Kudos
Message 8 of 9
(4,237 Views)

I still don't understand which data you expect to share and where, which means I still don't know if the SEQ ref has to be part of the object, or whether you can stuff the entire object into the ref.

 

In any case, when you use a SEQ, you need to manage all the data using DeQ and EnQ, each DeQ must have a corresponding EnQ and DeQs should have an infinite timeout. Like I said, search for examples. 

 

If a loop only needs commands from an actual queue (not a SEQ), then you can simply use an infinite timeout for its DeQ. It will sleep until the queue has something.


___________________
Try to take over the world!
0 Kudos
Message 9 of 9
(4,199 Views)