12-15-2011 01:53 PM
OK, I think I got the idea (by reading again your last posts). the producer loop will be my SUbVI, so I should declare a control termial with a ref to a queue...
Let me try, I'll come back to you...and hopfully, I'll make it right...
yoyo
12-15-2011 02:20 PM
OK guys, it was quite easy indeed. I was not used to handle queues, but it looks good now, and it works perfectly once we got the tip.
So thanks a lot for your time, and see you soon.
Yoyo87
LV rooky
12-15-2011 02:25 PM
Queues are one of my favorite constructs in LV.
THey are fast reliable and very flexible.
Take some time to review the help for the various Q operations to understand how they behave when the queue is empty the queue ref is invalid etc.
And have fun!
Ben
12-15-2011 02:30 PM
The attached example below are not intended to work.. Just to give you an idea of how the main talks with the sub-vi..
(sorry got called into a meeting...) Here's the post (a bit late... probably other examples...)
12-15-2011 02:40 PM
@Ray.R wrote:
NO!! NO!! NO!!!
DO NOT USE GLOBAL VARIABLES!!
It is not a good idea. The queue is an appropriate method. Using Global is NOT!!
And yes... I was screaming..
Zekasa, being a CLD, you should know better!
Hello Ray, and everyone there,
Ray,
Hope your voice is good now (after screaming on me), any way, I am 100% sure that the global variable solves the problem, and u start screaming "not use the global variable" even before you know that there is a "SUBVI with a loop" in the application.
Also, I know that the developer should avoid using global variable and I know the problems that may rise because of using the global variables. However, without having the details of the code, you can not select the most suitable way to solve the problem.
Finally, I am very sorry if my suggestion was not the most suitable way to solve the problem mentioned. By the way, CLD certified person also does mistakes. I am glade, because there are people like you and Ben who lead other developers to the right way of coding.
Thank you all. I am sorry again.
12-15-2011 03:05 PM
@Zekasa wrote:
@Ray.R wrote:
NO!! NO!! NO!!!
DO NOT USE GLOBAL VARIABLES!!
It is not a good idea. The queue is an appropriate method. Using Global is NOT!!
And yes... I was screaming..
Zekasa, being a CLD, you should know better!
Hello Ray, and everyone there,
Ray,
Hope your voice is good now (after screaming on me), any way, I am 100% sure that the global variable solves the problem, and u start screaming "not use the global variable" even before you know that there is a "SUBVI with a loop" in the application.
Also, I know that the developer should avoid using global variable and I know the problems that may rise because of using the global variables. However, without having the details of the code, you can not select the most suitable way to solve the problem.
Finally, I am very sorry if my suggestion was not the most suitable way to solve the problem mentioned. By the way, CLD certified person also does mistakes. I am glade, because there are people like you and Ben who lead other developers to the right way of coding.
Thank you all. I am sorry again.
Ray get a little excited when the topic of globals come up so we just have to wait for him to calm down.
Sharing data between loops using globals would be a night mare. How would the loop pull from the global know when there is new data in it? If we say the consumer will push an empty array to it, that could be stepped on by the producer loop or vise versa so you either get duplication or loss of data. You could start adding semaphores but now life get complicated and we would only be "rolling our own" AE or queue.
AE's could be coded to empty themselve when read so race condition avoided. Similar with queues. Review some of those threads in the Breakpoint to see how we came to the decision that globals are evil beasts that should only be let out of their cages in very specific condtions (single writter).
You don't have to appologize. Just keep having fun.
Ben
12-15-2011 03:22 PM
Thanks Ben,
I am reading the Breakpoints right now. However, could you please advice what do you mean by "Single writer"? I have more than one meaning for it in my mind,
Is it mean that I have to have one instance from this global variable which has write access mode and all the other instances are in read access mode? Or does it mean that I have to write to the global only once?
12-15-2011 03:43 PM
@Zekasa wrote:
Hope your voice is good now (after screaming on me)
Yes.. it's good now... Not from screaming, but from laughing!
, any way, I am 100% sure that the global variable solves the problem, and u start screaming "not use the global variable" even before you know that there is a "SUBVI with a loop" in the application.
Ben described why it's not a good idea. How do you synchronize data between the two loops? Plus, there are many other threads that discuss the Global abuse, where it is used for data passing. Not a good idea...
Also, I know that the developer should avoid using global variable
Then they should not have been mentionned 😉 lol!
and I know the problems that may rise because of using the global variables. However, without having the details of the code, you can not select the most suitable way to solve the problem.
As you get experience in these forums, you start developing that 6th sense..
By the way, CLD certified person also does mistakes.
Everybody does..
I am glade, because there are people like you and Ben who lead other developers to the right way of coding.
It's part of the fun..
Thank you all. I am sorry again.
Never appologize.. You need to get your feet wet... Just be glad smercurio or Dario didn't get to you first.. 😄
And Welcome!
12-15-2011 03:45 PM
Yes, I think it would be quite a mess to use global variables, although it was one possibility in my mind. I guess reading continously the global variable in the main VI, as well as updating it in the subVI would work, but it is not a proper use of ressources I guess...Queues do the job qin a clean way, as they force to deal with data in an organized way, when data are available only.
Thanks also for the example dude 🙂
I just implemented my program using queues (it's a measurement routine having 6 different measurement modes, each defined in a sub-VI). I use events to deal with the menu.
Cheers,
Yoyo
12-15-2011 03:45 PM
@Ben wrote:
Ray get a little excited when the topic of globals come up so we just have to wait for him to calm down.
I never get excited...
Sharing data between loops using globals would be a night mare.
That.. Is an understatement...
AE's could be coded to empty themselve when read so race condition avoided. Similar with queues. Review some of those threads in the Breakpoint to see how we came to the decision that globals are evil beasts that should only be let out of their cages in very specific condtions (single writter).
Ben,..... it's not time to start complicating things... I would then have to introduce semaphores and maybe rendez-vous...
You don't have to appologize. Just keep having fun.
😄
Ben