This is an unusual thread question because it's not about thread
programming per se but rather thread _auditing_. I'm working on a
process auditing tool (think strace but put to a different purpose).
Imagine that a threaded program is run twice under control of this
auditor and the results are left in two output files "trace1" and
trace2". I need to be able to "match up" the threads between trace1 and
trace2 for comparison purposes. And BTW, for now I only want to consider
pthreads; if the answer can be adapted to other implementations I can
probably handle that myself later on.
The obvious answer is to compare thread ids but this breaks down pretty
quickly. Some platforms issue random thread ids while others increment
from 1, but even on the latter type, due to the basic asynchronous
nature of threads, thread #3 in one run might be #4 in another.
Right now the best I can think of is a combination of (1) the address
from which pthread_create() was called, (2) the address of the
start_routine, and (3) the address of the argument to the start_routine.
It seems to me that, though it's possible for that same combination to
occur multiple times in the same process, even if they did the threads
would be logically interchangeable (i.e. they'd be doing the same thing
so it would be ok to treat them the same).
I can see at least one flaw in the above scheme; the data that the 'arg'
pointer address could change even if the pointer itself didn't. I don't
see an answer to that.
It might make sense to use the first argument to pthread_create (the
address to which the thread id is written, as opposed to the id itself)
as well, since I can't see it usually making sense to write multiple
thread ids to the same place.
These are my ideas; does anyone have better ones? Or is this by chance a
problem with a do***ented solution?
Thanks,
Arch Stanton


|