Re: [DynInst_API:] [PATCH] proccontrol: Avoid a destructor race on Counter::locks


Date: Wed, 21 May 2014 09:47:39 -0500
From: Bill Williams <bill@xxxxxxxxxxx>
Subject: Re: [DynInst_API:] [PATCH] proccontrol: Avoid a destructor race on Counter::locks
On 05/16/2014 07:01 PM, Josh Stone wrote:
On 05/16/2014 04:03 PM, Josh Stone wrote:
+Mutex<false> * Counter::locks = new Mutex<false>[Counter::NumCounterTypes];
  int Counter::global_counts[Counter::NumCounterTypes];

FWIW, I considered ditching the mutexes and making global_counts[] use
atomic<int>, but we don't yet live in a world where that is portable.

RHEL6 doesn't have boost::atomic.  It does have std::atomic, but it's
found in <cstdatomic> rather than <atomic>.  On Windows, the builders
are using VS10, which doesn't have std::atomic.  At least there we could
use new enough boost for boost::atomic.  Or either could use intrinsics,
via GCC __sync_fetch_and_add or Windows InterlockedAdd, but that's not
even trying to be portable.

So rather than a bunch of platform ifdefs, I chose to just make the
existing mutexes work more consistently.
_______________________________________________
Dyninst-api mailing list
Dyninst-api@xxxxxxxxxxx
https://lists.cs.wisc.edu/mailman/listinfo/dyninst-api

Atomics would be delightful, but I agree that now is not the time.

We could of course replace the array of locks with a vector<Lock>-derived class whose sole purpose is to have its destructor wait for the process to become single-threaded again, but really, leaking at exit should be harmless.

--
--bw

Bill Williams
Paradyn Project
bill@xxxxxxxxxxx
[← Prev in Thread] Current Thread [Next in Thread→]