This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Unexpected value-at for NULL'd pointer with pthreads
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Jeffrey Walton <noloader at gmail dot com>
- Cc: Kyle Harper <kylejharper at gmail dot com>, "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Fri, 21 Aug 2015 19:30:30 +0100
- Subject: Re: Unexpected value-at for NULL'd pointer with pthreads
- Authentication-results: sourceware.org; auth=none
- References: <CAPcbWWxx3g9Uk9sn5jgG1GgmxSk1fjy5ybHKuRMzdKN3LJqt2Q at mail dot gmail dot com> <CAH8yC8nSNMGkbLWWcToBX6ZP5ygFFVqjKOmjq_pnvvFmfnxqSA at mail dot gmail dot com>
On 21 August 2015 at 19:25, Jeffrey Walton wrote:
> From the sounds of it, it sounds like its the same issue that used to
> occur with the double-checked locking initialization pattern. See, for
> example, http://preshing.com/20130930/double-checked-locking-is-fixed-in-cpp11/.
Except that nothing is read outside the critical section guarded by the mutex.
> If this is the case, then use a memory barrier to ensure the write
> completes after setting the pointer to NULL.
pthread_mutex_unlock should be a release operation and
pthread_mutex_lock should be an acquire operation.