LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to change only one element of array in network variable

Hello to everyone...

I have a little problem that I can't solve...

I have one network variable(array of DBL) and multiple writers and readers. Each writer change only one element of array in variable. The easiest way to do it is to read whole variable, change desired element and write whole array again in variable. But the problem occurs if I have multiple writers, because they block each other and the values of other writers does not affect array in variable.

My question is how can I change only one element of array in network variable and at the same time allow other writers to do the same? Multiple writers, one variable of array, each writer can change only one specified element of array in variable, all writers can change their element at the same time. Is it possible?

thanks in advance...
0 Kudos
Message 1 of 8
(3,442 Views)

Hi,

 

If each user can only change one of the elemenst (it seems to me that there is no element that can be changed by two users), have you thought of creating multiple variabes instead of only one?

I don't think you can do it in the way you're trying to do - If you have multiple writers writing randomly, you will most probably run into race conditions.

 

Paulo

0 Kudos
Message 2 of 8
(3,431 Views)
Yes, that is correct, no element can be changed by two users. In my case I can't create multiple variables because I have random number of writers. I don't know in advance how many writers there will be and because of that I can't guess how many variables I should have.

Is there any possibility to have one variable for multiple writers? If every writer writes only on one specific element and if I could avoid a problem blocking writing of other writers it would be perfect. Any chance to do his?

Thanks
0 Kudos
Message 3 of 8
(3,415 Views)
Hi, The problem is: you have to read before you write. And between your read and your write somebody may have writen and that data will be lost. The only thing I think of is creating a boolean shared variable, that will act as a semaphore to the writers. Put it on before you read and off after you write and check if it is off before entering this process. Hope this helps, Paulo
0 Kudos
Message 4 of 8
(3,403 Views)
Hi,

that is exactly what I did. It works fine, but the only problem is now speed of whole process. With every additional writer the whole process becomes slower and slower. Its not optimal solution but it works ok.

I need solution that it gaves me abbility of multiple writing into array at the same time. I hope such solution exists.

Regards...
0 Kudos
Message 5 of 8
(3,398 Views)

Hi,

 

I don't think you can do that.

The shared variable is a resource external to your application that may be changed from different locations, so you will allways have to read the entire array before writing.

 

Is it only used to read and write from your LabVIEW program?Or are you also publishing the data to external sources?

If you are only using it in the application, consider using LabVIEW functional globals. That will give you an increase in performance.

 

Best Regards,

Paulo

0 Kudos
Message 6 of 8
(3,390 Views)
Hi,

yes I am publishing data also to external sources, so functional globals will not work. Thanks for your effort.

Regards,
Janez
0 Kudos
Message 7 of 8
(3,385 Views)

Hey RoboButler,

 

  A solution for Your problem could be the multiple variables and not one that is an array. It is not a problem that  You don't know how much You will have as creating shared variable can be done programatically. You may find an example on the link below on this topic:

 

http://decibel.ni.com/content/docs/DOC-2031

 

Hope it helps!

 

Best regards,

 

David Varga

Applications Engineer

NIH

0 Kudos
Message 8 of 8
(3,372 Views)