03-25-2013 12:52 PM
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
Solved! Go to Solution.
03-25-2013 01:07 PM - edited 03-25-2013 01:08 PM
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.
03-25-2013 01:13 PM
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.
03-27-2013 07:03 AM
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
03-28-2013 12:10 AM
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.
03-28-2013 05:39 AM
Yes, sure.
The code I attached I think is overcomplicated now. I've finished with semaphores anyway.
03-28-2013 06:25 AM
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 )
03-28-2013 06:47 AM
@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.
03-28-2013 07:36 AM
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.
03-28-2013 07:37 AM - edited 03-28-2013 07:39 AM
@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
EDIT:
@@crossrulz Queues seems like an option to I only don't have experience with them.