Yossi Lev
2010-May-12 03:19 UTC
[dtrace-discuss] Accessing an array of global indicators concurrently (by multiple threads)
Hi
I know that global variables in DTrace are unprotected, and that
generally accessing them by multiple threads is unsafe. However, I
think that I have a case in which it would be o.k to share a global
variable between threads, and wanted your advice about that.
In my case I need a 0/1 indicator that goes once from 0 to 1. Thus, all
the threads may run the following DTrace clause:
int indicator;
<some probe that may fire for multiple therads>
/indicator == 0/
{
indicator = 1;
}
I don''t really know how global variable are implemented in DTrace, but
I
believe that this usage pattern should be safe, and guarantee that the
variable at the end of the run is 1 if and only if the above probe fired
for at least one thread --- right? (Even though the reading of
indicator in the predicate is not atomic with writing it, the worst that
can happen is that multiple threads will write the variable to 1
concurrently, which I hope is safe.)
Now, for the more tricky question: what if I would like to use the same
pattern with an associative array, where each element in the array is a
global indicator? That is, the clause above would look something like:
int indicators[int];
<some probe that may fire for multiple therads>
/indicators[arg0] == 0/
{
indicators[arg0] = 1;
}
Is it still safe? The main reason I''m asking is that I do not know how
associative arrays are implemented in DTrace, and I can definitely
imagine an implementation that will make the above example unsafe
(e.g. if the array is implemented with a hashtable that can overflow and
be resized without taking into account concurrent lookup/assignments by
other threads). Can someone tell me if the above pattern is safe?
What I basically need is to keep track of whether an event happened and
change the script behavior once it does, but there are many different
events which is why I would like to use an array of global indicators,
indexed by the event id.
Thanks,
Yossi
--
This message posted from opensolaris.org