Jump to content

Access the same object from parallel loops


Recommended Posts

What's the best way to access the same object from parallel loops? And I mean THE same object not copies of the same object, because so far this is the only thing I've achieved, so updates from one loop do not make it into the other.

Thanks in advance, Mike

Link to comment

What's the best way to access the same object from parallel loops? And I mean THE same object not copies of the same object, because so far this is the only thing I've achieved, so updates from one loop do not make it into the other.

Thanks in advance, Mike

Hi Mike

You have a bunch of options to create by reference (ByRef) objects all with their pros and cons, here are some...

  • Use LVOOP with Data Value References and the In Place Element (IPE) (new in 2009)
  • Create a Single Element Queue (SEQ) and create your own ByRef API
  • Use a third party tool such as Endevo GOOP, Sciware etc...

Link to comment

What's the best way to access the same object from parallel loops? And I mean THE same object not copies of the same object, because so far this is the only thing I've achieved, so updates from one loop do not make it into the other.

What is the best way to access the same array from parallel loops? Whatever answer you give here, use the same mechanism for objects.
Link to comment

LVOOP is by-value, just like almost everything else in LabVIEW, so don't think of it like "how do I access objects across parallel loops", instead think of it as "how do I acess <anything> across parallel loops".

LVOOP is by-value, just like almost everything else in LabVIEW, so don't think of it like "how do I access objects across parallel loops", instead think of it as "how do I acess <anything> across parallel loops".

...just noticed that Aristos already answered the question better than me :)

Link to comment

What's the best way to access the same object from parallel loops? And I mean THE same object not copies of the same object, because so far this is the only thing I've achieved, so updates from one loop do not make it into the other.

I agree with everything previously said in this thread, so let me add something a little different.

You are asking the wrong question. Instead of "how do I access the same object in parallel loops," you need to ask "how do I want this class to behave?" Broadly speaking, there are three possibilities:

  1. By-val. Each new instance creates a new object. Branches create a copy of the object. (This is the "normal" way.)
  2. By-ref. Each new instance creates a new object. Branches refer to the same object.
  3. Singleton. All instances and branches refer to the same object.

(You can create classes in which some data is by-val, some is by-ref, and some is singleton, but that's beyond the scope of this post.)

By first defining the expected behavior for the class as a whole, you can build that functionality into the class itself in a way that doesn't break your application in other areas. If the class' built-in behavior doesn't fit your requirements at a certain point in the code, you add other code at the application level to fit the behavior you need there.

Suppose your program will have lots of instances of a class, so you decide it should be by-val to simplify the programming. But in this one place you need by-ref behavior so you can access the object from parallel loops. That's where you would use the DVR or other techniques to enable that functionality. On the other hand, if it makes sense for the class itself to be by-ref, you can build that into the class members in a way that class users don't have to worry about DVR's, IPE's, queues, FG's, etc. The class user just needs to know that it's a by-ref object, and branches don't create copies.

[Edit - Changing an object's behavior can only be done in a single direction. (By-val -> By-ref -> Singleton) You can make a by-val object behave like a singleton, but you can't make a singleton behave like a by-val object.]

Edited by Daklu
  • Like 1
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
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.