From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10771 invoked by alias); 5 Mar 2013 14:35:06 -0000 Received: (qmail 10698 invoked by uid 22791); 5 Mar 2013 14:35:05 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-oa0-f42.google.com (HELO mail-oa0-f42.google.com) (209.85.219.42) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 05 Mar 2013 14:35:00 +0000 Received: by mail-oa0-f42.google.com with SMTP id i18so11014330oag.15 for ; Tue, 05 Mar 2013 06:35:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:x-gm-message-state; bh=ow4BcfMRlrCAY5ChZMM//yWHRIA8ydXUvIcXfVspru8=; b=Zo264s1YvbwOlpqqT+8BsQt5MjvR3FbIr/jC18rn5eCxJlrzrrynMwLo/7BsDJbvud HCyQdnsElbEsKpoJqMJy3kiaBlBizMVqDtQiIy0WCFBWndVIgEk7i94mcpz5qLj//v83 rY9O1GioCJB6xn4GAxNe+/sQsV4f27AoJwiySzzT2Iwz38pClb2DIkv50LDBRSkIbYtQ dl5x2FcYhcZsPlUjLQR693S3QMq2HNA3PKztdAGNLFvOU+eLxlz7H9lJy6GGwYxjvU7v atg/S2mGprTokZMfJRajsaXKkp0sQK4nFwVk0p1jEZG07k/w5UOU0ceC2xzYpljgR0gu ZjkA== MIME-Version: 1.0 X-Received: by 10.182.5.199 with SMTP id u7mr6205160obu.45.1362494100238; Tue, 05 Mar 2013 06:35:00 -0800 (PST) Received: by 10.182.5.137 with HTTP; Tue, 5 Mar 2013 06:35:00 -0800 (PST) In-Reply-To: References: Date: Tue, 05 Mar 2013 14:35:00 -0000 Message-ID: Subject: Re: Question on volatile functions and GCC From: Ian Lance Taylor To: David Paterson Cc: Jonathan Wakely , noloader@gmail.com, gcc-help@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQnPeNrgZE/jACsX8rj2dDvVbf99Yl/bpDidWWhI4RVhYBiuK+xCvcUEyNUE6YKz25tP+eP37ceyaqV/jOFY4Y2JbTisMQX1wAPGKRdspmq06IbphzAqgQUU5IYSISk/2W3Q34PfGaT2s9QCi/lXpLPYYUfqhk4mm3kyQ/hT6da079ycIuYpUB1q8OoRNNf2ULUlAjRM X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2013-03/txt/msg00040.txt.bz2 On Tue, Mar 5, 2013 at 1:58 AM, David Paterson wrote: > On 5 March 2013 09:40, Jonathan Wakely wrote: > >> volatile is not for multithreading, you need proper synchronization >> for interthread communication. > > Not always. For very simple, non-critical uses you can just use a > volatile flag-type variable. Cheap and nasty, I agree, but useable. If your code has a race condition before you add a volatile qualifier, it will still have a race condition after you add the qualifier. If you want a simple flag variable, don't use volatile; use __atomic_load and __atomic_store. Ian