Jump to content

Questions about LVOOP and race conditions


Recommended Posts

I'm still getting up to speed with LVOOP concepts, mainly translating my brain views of other OOP languages into what LVOOP requires. Having read the stickied thread and attachments, I'm still hazy about race conditions.

Here is the example I conjured:

Class FileLineReader: # reads a text file line by line

  • Members:
    • file refnum
    • other fluff about the file

    [*]Methods:

    • OpenFile() - Opens a file
    • GetNextLine() - returns string
    • SeekToLine() - seeks to a given line in text file
    • more fluff

I create an instance of this class.

Can I have worker threads that each have a copy via wire of this object, where each worker is called GetNextLine()? How is LabVIEW enforcing that my file refnum isn't being hit by 2 reads at same time?

I know there are other ways to design this to avoid contention but I'm curious about this edge case.

Link to comment

QUOTE (Matthew Zaleski @ Mar 21 2009, 07:41 PM)

Can I have worker threads that each have a copy via wire of this object, where each worker is called GetNextLine()? How is LabVIEW enforcing that my file refnum isn't being hit by 2 reads at same time?

The short answer is it doesn't.

But there are subtleties. Assuming GetNextLine() is not re-entrant, only one task will ever be able to call the method at once since there will be only one copy of the VI in memory. So there's some built in synchronization right there, but it's not really OOP that's buying you that, the principle is the same for any VI with default entrancy.

Something to consider: you have multiple methods that would seem to operate on the file reference, like SeekToLine(), and maybe other "fluff". So even though LabVIEW will keep you from calling GetNextLine() simultaneously in two places, you'll likely still need to build some kind of synchronization mechanism to ensure that say, GetNextLine and SeekToLine are not called at the same time from different tasks. There are many ways, mzu mentioned the singleton pattern. Properly build a semaphore into your class will also work.

Also be aware of the context of split wires if you have non-reference data in your class, or if references change.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.