|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How To use Global variables and sequences
Whats the proper way to use global variables? I've used quite a few in my project to pass variables between subvi's. In another thread, (here), Greg said "you will get burned by parallel updates or race conditions."
I made sure I'm only writing the variables in one place. So I think I'm ok with the parallel updates. I don't think I'd have an issue with a race condition. But if I did, how should it be handled? |
|
#2
|
|||
|
|||
|
Re: How To use Global variables and sequences
It is all about using the right tool for the right job. Are you sure you want a global? Would a queue, a notifier or a user event work better for your application?
User events notifiers and queues can be passed around to subVIs, which makes code re-use easier later. A queue allows you to guarantee that you will get all the data across, but is typically one write/one read. A notifier only pushes data when you are ready to read it - if the listener is busy, it (intenionally) drops the write on the floor. A user event is one write/multi read, but harder to use. A global is easy to use, but doesn't have some of the extra features of the other options. Also, always lump related data together - if you use something as a cluster, make it a cluster. This will ensure that the entire kit'n'kaboodle gets written simultaneously, and will prevent you from reading half new and half old data. |
|
#3
|
|||||
|
|||||
|
Re: How To use Global variables and sequences
We're using globals to communicate between teleop and periodic tasks, and to hold information to be sent in the dashboard data. I gave some thought to using other features such as queues or events, but I couldn't see a good way to pass the queue or event itself around without using a global variable anyway.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|