library: ensure thread safety for all static variables
Even though we we had to abandon the master branch top multi-thread effort and even though the newlib version of a multi-threaded top provides no real benefit, that whole exercise was not wasted. Rather, it has revealed some deficiencies in our library which this addresses. If two or more threads in the same address space tried to access the same api simultaneously, there is a good chance some function-local static variables will yield some of those renowned unpredictable results. So, this patch protects them with the '__thread' storage class. Reference(s): https://www.freelists.org/post/procps/a-few-more-patches,7 Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
@@ -1123,7 +1123,7 @@ static int pids_stacks_fetch (
|
||||
#define n_alloc info->fetch.n_alloc
|
||||
#define n_inuse info->fetch.n_inuse
|
||||
#define n_saved info->fetch.n_alloc_save
|
||||
static proc_t task; // static for initial zeroes + later dynamic free(s)
|
||||
static __thread proc_t task; // static for initial 0's + later free(s)
|
||||
struct stacks_extent *ext;
|
||||
|
||||
// initialize stuff -----------------------------------
|
||||
@@ -1367,7 +1367,7 @@ PROCPS_EXPORT struct pids_stack *fatal_proc_unmounted (
|
||||
struct pids_info *info,
|
||||
int return_self)
|
||||
{
|
||||
static proc_t self;
|
||||
static __thread proc_t self;
|
||||
struct stacks_extent *ext;
|
||||
|
||||
/* this is very likely the *only* newlib function where the
|
||||
@@ -1404,7 +1404,7 @@ PROCPS_EXPORT struct pids_stack *procps_pids_get (
|
||||
struct pids_info *info,
|
||||
enum pids_fetch_type which)
|
||||
{
|
||||
static proc_t task; // static for initial zeroes + later dynamic free(s)
|
||||
static __thread proc_t task; // static for initial 0's + later free(s)
|
||||
|
||||
errno = EINVAL;
|
||||
if (info == NULL)
|
||||
|
Reference in New Issue
Block a user