Jump to content

Open file and Read file may occur at same time


Recommended Posts

Scenario of a given program I'm debugging:

There's a file called Howdy.txt. It either has 7 characters in it or nothing.

Parallel loops...

Loop 1 writes to Howdy.txt file every 2 minutes to 30 minutes.

Loop 2 opens up Howdy.txt every 1000mS and looks at it - to see if it's been written to. This happens all the time, 24/7.

With this scenario, it appears there's a small chance the file can be open at the same time in two places. Is this common? Can it cause problems?

The VI's are Write Characters To Fle and Read Characters From File.

Thanks!

Richard

Link to comment

QUOTE(BrokenArrow @ Jun 19 2007, 09:03 AM)

Scenario of a given program I'm debugging:

There's a file called Howdy.txt. It either has 7 characters in it or nothing.

Parallel loops...

Loop 1 writes to Howdy.txt file every 2 minutes to 30 minutes.

Loop 2 opens up Howdy.txt every 1000mS and looks at it - to see if it's been written to. This happens all the time, 24/7.

With this scenario, it appears there's a small chance the file can be open at the same time in two places. Is this common? Can it cause problems?

The VI's are Write Characters To Fle and Read Characters From File.

Thanks!

Richard

Provided they both use seperate "opens" and file ref's AND ther is only one writter*, you should be OK.

The file system (as realized throught the LV API's) track the file pointer seperately for each ref.

* There was a bug in LV 7.X where LV could mix up the file ref nums (which is a big problem if the two files are data log files of different types! You do not want to try and untagle one of these.)

Ben

Link to comment

QUOTE(Ben @ Jun 19 2007, 09:09 AM)

Ben,

By "use seperate "opens"" do you mean are the VI's different that do the opening? There's definately one write.

QUOTE(tcplomp @ Jun 19 2007, 09:14 AM)

A better solution is the fileinfo primitive:

filedir.gif

If I were you I'd use a messaging system, but since you are debugging most likely you inherited the code :headbang:

Ton

That's a great idea Ton. That way, it's not opening and closing the file just to see if it has changed. Or, if it does open it, at least it's a different open as Ben recommended.

-Richard

-----------------------------

p.s. Is writing to a file a common way to share a variable? (keep in mind this is 5.1)

Link to comment

ZITAT(BrokenArrow @ Jun 19 2007, 03:03 PM)

Parallel loops...

Loop 1 writes to Howdy.txt file every 2 minutes to 30 minutes.

Loop 2 opens up Howdy.txt every 1000mS and looks at it - to see if it's been written to. This happens all the time, 24/7.

With this scenario, it appears there's a small chance the file can be open at the same time in two places. Is this common? Can it cause problems?

The VI's are Write Characters To Fle and Read Characters From File.

You can do this when you open the file in loop 2 only as "read only". Then it should work.

Wolfram

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.