Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762949AbXJYX5r (ORCPT ); Thu, 25 Oct 2007 19:57:47 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1759004AbXJYX5k (ORCPT ); Thu, 25 Oct 2007 19:57:40 -0400 Received: from smtp2.linux-foundation.org ([207.189.120.14]:58976 "EHLO smtp2.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758449AbXJYX5j (ORCPT ); Thu, 25 Oct 2007 19:57:39 -0400 Date: Thu, 25 Oct 2007 16:57:34 -0700 (PDT) From: Linus Torvalds To: Andi Kleen cc: Nick Piggin , Linux Kernel Mailing List Subject: Re: Is gcc thread-unsafe? In-Reply-To: <200710260142.37902.ak@suse.de> Message-ID: References: <200710251324.49888.nickpiggin@yahoo.com.au> <200710260116.10904.ak@suse.de> <200710260142.37902.ak@suse.de> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1231 Lines: 29 On Fri, 26 Oct 2007, Andi Kleen wrote: > > The conditional add/sub using carry trick is not generally bogus. > But for registers it's a fine optimization. For registers it's fine. For memory, it's a disaster. It's more than just dirty cachelines and introducing race conditions, it's also about protection and dirty pages. So even in user space, to even be correct in the first place, the compiler would need to make sure that the variable is writable at all (or you might take a SIGSEGV), but I guess that gcc just assumes it is, at least for globals (or gcc could depend on seeing *other* writes that are done unconditionally). More likely, the compiler people don't even care, because "the C standard doesn't specify that behaviour" - ie things like write-protected memory or garbage collection based on dirty/accessed bits are outside the scope of what the language specifies. Much less things like pthreads or other synchronization primitives in threads. Linus - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/