From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15300 invoked by alias); 5 Sep 2012 08:05:48 -0000 Received: (qmail 15272 invoked by uid 22791); 5 Sep 2012 08:05:47 -0000 X-SWARE-Spam-Status: No, hits=-5.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-pz0-f43.google.com (HELO mail-pz0-f43.google.com) (209.85.210.43) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 05 Sep 2012 08:05:34 +0000 Received: by daku36 with SMTP id u36so192283dak.2 for ; Wed, 05 Sep 2012 01:05:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.68.240.66 with SMTP id vy2mr52069449pbc.73.1346832333218; Wed, 05 Sep 2012 01:05:33 -0700 (PDT) Received: by 10.68.36.72 with HTTP; Wed, 5 Sep 2012 01:05:33 -0700 (PDT) In-Reply-To: <20120904215129.GA30731@ednor.casa.cgf.cx> References: <504612A3.6070605@cs.utoronto.ca> <50466981.70005@gmail.com> <20120904215129.GA30731@ednor.casa.cgf.cx> Date: Wed, 05 Sep 2012 09:09:00 -0000 Message-ID: Subject: Re: limitations of TLS using GCC's __thread keyword and Cygwin From: =?UTF-8?Q?V=C3=A1clav_Zeman?= To: cygwin@cygwin.com Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2012-09/txt/msg00065.txt.bz2 On 4 September 2012 23:51, Christopher Faylor wrote: > On Tue, Sep 04, 2012 at 10:50:09PM +0200, V??clav Zeman wrote: >>On 09/04/2012 04:39 PM, Ryan Johnson wrote: >>> On 04/09/2012 8:58 AM, V??clav Zeman wrote: >>>> Hi. >>>> >>>> I am am porting a library that can use the __thread keyword in its >>>> internals to provide thread local storage. Now, with MSVC there is a >>>> limitation on pre-Vista Windows (see [1]) that DLLs using >>>> __declspec(thread) (MSVC equivalent of GCC's __thread) cannot be >>>> loaded using LoadLibrary() because pre-Vista Windows allocate the TLS >>>> declared that way only on process startup. Vista and later Windows do >>>> not seem to have the limitation. Since Cygwin officially still >>>> supports at least Windows XP, I want to provide a library that works >>>> there as well. >>>> >>>> Does Cygwin's GCC and its TLS emulation work around this problem? IOW, >>>> are Cygwin DLLs using TLS declared using __thread keyword safe to be >>>> loaded using LoadLibrary()/dlopen() or are they not safe to be loaded >>>> that way? >>>> >>>> [1] http://msdn.microsoft.com/en-us/library/2s9wt68x.aspx >>>> >>> I suspect it's not a problem, but if I were you I'd write a simple >>> test program to see. Unfortunately, TLS in general seems broken on my >>> machine when I tried it, but that might be due to my home-brew gcc >>> being configured wrong or something. >>I would have done that already but I do not have any Windows XP machine >>to try this on. > > I don't believe that __thread is implemented on Cygwin. Adjust your beliefs. :) It is implemented and it works correct as far as I can tell. It implements TLS using calls to __emutls* routines. What I am unclear about is whether the implemention works around the limitation mentioned in the MSDN link or not. -- VZ -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple