From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3645 invoked by alias); 11 Jul 2012 08:26:28 -0000 Received: (qmail 3600 invoked by uid 22791); 11 Jul 2012 08:26:27 -0000 X-SWARE-Spam-Status: No, hits=-4.7 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 11 Jul 2012 08:26:14 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1SosFO-0001Di-Oo from Maxim_Kuvyrkov@mentor.com ; Wed, 11 Jul 2012 01:26:10 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Wed, 11 Jul 2012 01:25:16 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.1.289.1; Wed, 11 Jul 2012 09:26:09 +0100 Subject: Re: [PATCH] Unify pthread_spin_[try]lock implementations. MIME-Version: 1.0 (Apple Message framework v1278) Content-Type: text/plain; charset="us-ascii" From: Maxim Kuvyrkov In-Reply-To: <20120711081441.73BB22C093@topped-with-meat.com> Date: Wed, 11 Jul 2012 08:26:00 -0000 CC: Joseph S.Myers , Richard Sandiford , , libc-alpha Devel Content-Transfer-Encoding: quoted-printable Message-ID: <558BF34B-D55C-4E72-AE69-8B2822C1CCF8@codesourcery.com> References: <2109EAD5-BBE8-4C8C-8D61-0AF33290F240@codesourcery.com> <65B470D2-4D01-4BA1-AEC5-A72C0006EA22@codesourcery.com> <20120711081441.73BB22C093@topped-with-meat.com> To: Roland McGrath Mailing-List: contact libc-ports-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: libc-ports-owner@sourceware.org X-SW-Source: 2012-07/txt/msg00023.txt.bz2 On 11/07/2012, at 8:14 PM, Roland McGrath wrote: >> +int >> +pthread_spin_lock (pthread_spinlock_t *lock) >> +{ >> + while (atomic_compare_and_exchange_val_acq (lock, 1, 0) !=3D 0) >> + while (*lock !=3D 0) >> + ; >=20 > What's the inner loop for? My understanding is that this is an optimization. On many architectures at= omic_compare_and_exchange will synchronize memory across all CPUs, which wi= ll penalize other running threads. Spinning in a simple (*lock !=3D 0) loo= p will allow those threads to finish whatever they are doing faster and rel= ease the lock. -- Maxim Kuvyrkov CodeSourcery / Mentor Graphics