Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   NI LabVIEW (http://www.chiefdelphi.com/forums/forumdisplay.php?f=182)
-   -   How To use Global variables and sequences (http://www.chiefdelphi.com/forums/showthread.php?t=93366)

jrz126 08-03-2011 14:57

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?

EricVanWyk 08-03-2011 15:46

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.

Alan Anderson 08-03-2011 16:08

Re: How To use Global variables and sequences
 
Quote:

Originally Posted by EricVanWyk (Post 1036587)
User events notifiers and queues can be passed around to subVIs, which makes code re-use easier later.

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.


All times are GMT -5. The time now is 09:25.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi