05-26-2006 02:28 PM
Hi,
I would like to know when you access an array in a local variable, is it an atomic operation?
Thanks,
Mat |
05-26-2006 05:29 PM
Hi Mat,
the write to a local must be an atomic operation. Else the array you mentioned might result buggy: Consider writing to the local variable of an array at two locations on your block diagram without wiring any runtime dependeny to the write operations. If each write operation wires an array of a unique size (i.e. different from the size the other write operation does) and the write would not be atomic and thus interrupted by the scheduler - what would be the result if the write of the bigger array is interrupted in the middle of the write operation and now have the other write operation decrease the array size? What should the scheduler do when it wants to resume the write of the larger array? Especially as the memory that was once allocated has been freed in between? What to do if elements got lost that have already been written? So, these must be atomic operations. (Let me say that I cannot prove this as I do not the source code of LabVIEW. So everybody who wants to add his comments is invited to do so.)
Furthermore, in the scenario mentioned above, you cannot say which write executes first in LabVIEW, therefore nobody should program this on a block diagram.
This makes your question quite confusing. If you cannot predict the result -> Why putting this on the block diagram?
When reading from local variables LabVIEW always creates an in-memory copy of the data (which you can easily verify by profiling the buffer allocations). This must be atomic, too. If not, the read could e.g. contain the nonsense from the not-atomic-write outlined above.
And now my question (because you succeeded in getting me curious):
What kind of block diagram were you thinking of when this question populated your mind?
Best regards, Guenter
05-29-2006 08:08 AM
Hi,
I agree with you but I would like to know if it is, fore sure, atomic (Can someone at NI confirm this??!!).
I am developping a Real-time application with Timed-loops. The Times-loops have different priority levels and loop rates. The faster loops have a higher priority (for a rate-monotonic sheduling). I share data between the loops (which run on seperate threads). I don't want to use a RT-FIFO since the faster loop will read the value many times more than the slower one will write to it. That does not work with a RT-FIFO because with a FIFO once you read a value it is removed from the FIFO. I know I could use functionnal global variables (LV2 style global) but I don't whant to if I don't need to.
If writting and reading to an array are atomic operations then I can symply use local or global variables.
Thanks,
Mathieu
05-29-2006 11:23 AM
05-29-2006 12:13 PM
Thanks for the comments. I agree with you. However, I my case, race conditions and synchronization are not issues. Therefore, the only thing that matters to me is that the write and read operation of the array must be atomic. I know that I can implement that with a LV2 style global but I want to avoid it if possible.
If writing and reading to an array are atomic operations then I can simply use local or global variables.
All I need to know is: Is reading or writing an array in a local variable an atomic operation?
Thanks,
Mat
05-29-2006 12:44 PM
LabVIEW, C'est LabVIEW
05-29-2006 02:05 PM
Thanks Jean-Pierre. Did you find this out through experimention or is it stated somewhere in an NI document?
Regards,
Mathieu
05-29-2006 02:53 PM
LabVIEW, C'est LabVIEW
05-29-2006 03:53 PM
@JeanPierre wrote:
Apparently my signature removes any credentials to my status of Proven Active Veteran...
Consider yourself lucky. At least you still are a PAV. Look at poor Kennon Cotton.
Molly?
05-29-2006 05:23 PM
I think the issue with Kennon Cotton's role is that his "minutes online" value has gotten so big that it's negative now. (This is similar to what we saw in the past with Altenbach I believe.) With a negative "minutes online" it's having problems calculating the correct role. I have reported the issue. Thanks for bringing it to my attention.
Have a great day!