LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write to binary as reentrant VI

This may be a simple answer, but here goes.

 

I am implementing a reentrant VI (with maximum 30 clones), and all clones will be writting information to the same file (call it test.txt) multiple times. The attached code prepares the file so that any information written to it will be appended at the end (i.e. the pointer position will be at the end).

 

I don't know how this would behave under a reentrant case. I thought of "getting" and "setting" pointer position of the file before the "binary write" happens, but I'm worried about the race condition. i.e. by the time I "get" and "set" the pointer, another "write" operation could've happened from another clone.

 

Any thoughts appriciated.

 

kas 

0 Kudos
Message 1 of 22
(2,669 Views)
The only thought I have is to not make it reentrant. Perhaps you could use an IPES or a semaphore to keep multiple VIs from writing to the file at the same time, but you might as well just use the file reference in a "linear" fashion.
Message 2 of 22
(2,649 Views)

Well, using it as reentrant would greatly simplify my coding. If I'm still sticking to this, how would you implement the above example with IPES, semaphore or queues. 

 

Thanks 

Kas

0 Kudos
Message 3 of 22
(2,642 Views)

This sounds like the exact place to NOT use a reentrant VI.  I would recommend using an Action Engine to manage your test file.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 22
(2,640 Views)

Well, the data that each clone VI is handling could go up to 50MB (or more). I'm not very keen on using AE in this case, nor sending the data through a queue so that a non-reentrant VI or main VI saves it as the data comes. 

 

Thanks

 

Kas

0 Kudos
Message 5 of 22
(2,636 Views)

Oh, I see what you mean, now. The "write data to file.vi" will be called by different VIs and will write to different files. I thought you wanted them to write to the same file. As long as you pass in the file reference, reentrant is fine.

 

edit ...

 

Re-read the the OP - I don't see how you can expect multiple VIs to write to the same file at the same time.

0 Kudos
Message 6 of 22
(2,629 Views)

You have 1 resource you have to protect.  That is the point of the Action Engine.  All you really need in the AE is a case to open the file, a case to close the file, and a case to save the data.  This way there is no conflict of multiple places trying to save data to the same file.  All the AE is doing to saving the data.  You can manage the data however you want in the reentrant parts of the code.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 22
(2,626 Views)

"I thought you wanted them to write to the same file". 

Actually, this statement is correct.

0 Kudos
Message 8 of 22
(2,621 Views)

At the same time?

0 Kudos
Message 9 of 22
(2,617 Views)

"All you really need in the AE is a case to open the file, a case to close the file, and a case to save the data". 

As soon as you mentioned AE, I thought of using it in conjuction with data directly (hence my hesitation). Your solution however seems a way forward. 

 

Furthermore, would it be even better if I use the AE just to store/read the "refnum out" inside the while loop and keep the "write to binary" function outside the AE?.

 

Thanks 

 

Kas

0 Kudos
Message 10 of 22
(2,615 Views)