On Sat, 2008-04-05 at 11:26 -0700, Roland McGrath wrote:
Well, if we allocate at clone time then some things do get a bit
simpler. (Hmm, for some reason I was thinking that we still allocate in
do_setitimer() as well, but it doesn't look like it.)
Yeah, I checked that out. The one difference here is that that was a
race between do_exit() (actually release_task()/__exit_signal()) and
run_posix_cpu_timers(). While this race was the same in that respect,
there was also a race between all of the timer-tick routines that call
any of account_group_user_time(), account_group_system_time() or
account_group_exec_runtime() and __exit_signal(). This is because those
functions all dereference tsk->signal.
Erm, well, this isn't reorganizing the data structures per se, since
these are new data structures. Regardless, the way I did this was by
making the refcounted structure follow the lifetime of the task
structure. It's instantiated when needed and at that point each task
structure in the thread group gets a reference, which is released when
that task structure is destroyed. The last release destroys the data
structure.
The upshot of this is that none of the timer routines dereference
tsk->signal, so the races go away, no locking needed. From my
perspective this was the simplest solution, since lock dependency
ordering is _really_ a can of worms.
The solution was really very simple, in fact.
That's certainly a possibility, but it'll still require more code in the
timer routines to check whatever state there is.
I'll have to look at the code some more and thing about this. For the
other timer routines I would think that the second approach would be
better, but I still think that best of all is to not have to check
anything at all (except of course the presence of the structure pointer
itself).
Regarding the second approach, without locking wouldn't that still be
racy? Couldn't exit_state change (and therefore __exit_signal() run)
between the check and the dereference?
--
Frank Mayhar frank@exit.comhttp://www.exit.com/
Exit Consulting http://www.gpsclock.com/http://www.exit.com/blog/frank/http://www.zazzle.com/fmayhar*
--