LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Filling in an array from multiple threads

Solved!
Go to solution

Hi,

 

I was trying to find out the mechanism I could use to fill in a string array from multiple threads (a few while and for loops with different timings, within one process) asynchronously.

 

I went to Create->Property/Invoke Nodes->(...) but I couldn't find any properties/method I could use. Have I missed something?

 

For example how to programatically insert element into array at position x?

 

Shall I use semaphores as well, or FGV would be enough?

 

K

0 Kudos
Message 1 of 13
(3,232 Views)

The functional global will work.  There is a simple function called Insert Into Array.  A better option (depending on your exact requirements) might be to preallocate the array and use Replace Array Subset.


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
Message 2 of 13
(3,229 Views)

You can use the insert array function but if you use it in many places for a same array then each time the index of the element you inserted before would vary since it will just append the element inoto that particular index. If you want to maintain index of elements constantly and don't want that to be changed then you can initilalize the size of the array at the beginning and then use the Replace array subset to insert the element you want.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 3 of 13
(3,220 Views)

I think I'd need more help on it.

 

I can't fill the arrays.

 

Could you please drop a link to the example if posible?

 

Cheers

0 Kudos
Message 4 of 13
(3,179 Views)

It would be better if you can show what you have done. Please post an image of the code where you have the problem also you can attach the code in 2009 version if possible.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 5 of 13
(3,159 Views)

Yes, sure.

 

The code I attached I think is overcomplicated now. I've finished with semaphores anyway.

 

Capture.png

Download All
0 Kudos
Message 6 of 13
(3,148 Views)

The first thing i notice that the result of the array will be the data from one loop or that from the other, never that of both. 

Both loops work with a local copy of the array and you copy that local variable in the array. 
You can try to load the variabele from a reference inside the loop ( watch out do this inside the semafore ) 


Learning LabVIEW since January 2013
0 Kudos
Message 7 of 13
(3,139 Views)

@LordNobady wrote:

The first thing i notice that the result of the array will be the data from one loop or that from the other, never that of both. 


 

 That is false statement. Run the code attached and you see that the array consists of the data generated from both loops


@LordNobady wrote:

(...)

Both loops work with a local copy of the array and you copy that local variable in the array. 
(...)


 

Yes, it doesn't seem to be eficient way is it?

 


@LordNobady wrote:

(...)

You can try to load the variabele from a reference inside the loop ( watch out do this inside the semafore ) 


 

I don't understand your last statement.

 

0 Kudos
Message 8 of 13
(3,133 Views)

This actually looks like a perfect place to use Queues.  You can have multiple loops enqueue data (item to add to array).  You just need another loop to dequeue the data as it comes in.  This extra loop can also update your indicator so you don't have to use a property node (should be a local variable) to update the GUI.


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
Message 9 of 13
(3,125 Views)

@MimiKLM wrote:

@LordNobady wrote:

The first thing i notice that the result of the array will be the data from one loop or that from the other, never that of both. 


 That is false statement. Run the code attached and you see that the array consists of the data generated from both loops


Sorry that is becose i dit not check the sub vi. was not at a system with labview at the time. 

 

the last statement was with the first statement in mind it is not important at this moment.

 

the code below seems to be doing the same. and looks more clean

 

array filler.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

EDIT:

@Queues seems like an option to I only don't have experience with them. 

 


Learning LabVIEW since January 2013
0 Kudos
Message 10 of 13
(3,123 Views)