This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
working with private variables in a multi-threaded env
- From: Adam Irawan <the_sandman at rogers dot com>
- To: libc-alpha at sourceware dot org
- Date: Fri, 12 May 2006 17:28:41 -0400 (EDT)
- Subject: working with private variables in a multi-threaded env
Hello,
I'm working on a module that can be reduced to one
that will count how many times `foo' is called in a
user code. The module will scan through the user code,
and will add `counter++' before every call to `foo'.
The problem is that the user code is independent, and
a problem arises when it's threaded. It should be
obvious that `counter' is not threadsafe and may
record wrong results. Unfortunately, I can't use locks
since it will incur huge overhead in performance (
e.g., inside a huge for loop with a large number of
threads).
The solution I'm heading toward now is privatizing
`counter' to each thread (i.e., __is_thread). Does
anyone have any ideas/suggestions(/solutions? :-o) to
how would one go about collecting these private variables?