06-01-2006 03:00 AM
I have a multithreaded application with several parallel loops, and in some cases I want to use shared cluster variables to communicate between the loops. Race conditions are a problem if I want to write to a single cluster element. As far as I understand the only way to write to single cluster element is first reading from cluster, and secondly use the unbundled function to write to the single cluster element and then writing to the complete cluster. A race condition will arise if the loop is pre-empted in between these steps and if a second loop writes to the same cluster. LV2 variables will solve the problem, but this makes the programming more complex. So my question is: Is it possible to write to single cluster element in a single operation to avoid race condition?
Regards Per
06-01-2006 03:27 AM
06-01-2006 03:40 AM
06-01-2006 02:06 PM - edited 06-01-2006 02:06 PM
@Monza wrote:
As far as I understand the only way to write to single cluster element is first reading from cluster, and secondly use the unbundled function to write to the single cluster element and then writing to the complete cluster.
To only write to a single cluster element, you don't need to unbundle at all. A single "bundle by name" will do the trick. See image.
Message Edited by altenbach on 06-01-2006 12:06 PM
06-01-2006 02:23 PM - edited 06-01-2006 02:23 PM
Message Edited by daveTW on 06-01-2006 09:24 PM
06-01-2006 03:34 PM
06-02-2006 01:32 AM
06-02-2006 08:00 AM
....
But if you go through the trouble of putting in a sub-VI, then using a shift registerinstead of a globals is a simple modification.
By doing so you
1) pick-up the option to possibility of re-using buffers (if working with arrys)
2) loose the extra memory required to store copies of the global
3) never have to find out "which thread do updates of the Global take place in?".
I strongly urge going the LV2 route.
Ben