Re: localtime in Solaris 9 is not thread safe?

From: Andreas F. Borchert (comp.unix.solaris_at_expires-on-2005-03-16.usenet.andreas-borchert.de)
Date: 03/08/05


Date: Tue, 8 Mar 2005 07:12:17 +0100 (CET)

On 2005-03-08, Franklin Li <pengtaoli@hotmai.com> wrote:
> I'm using pthread(C++) programming in Solaris 9 and find that localtime is
> not thread safe. Is it true?

>From the NOTES section of the manual page of ctime(3c):

     The return values for ctime(), localtime(), and gmtime()
     point to static data whose content is overwritten by each
     call.

     [...]

     The asctime(), ctime(), gmtime(), and localtime() functions
     are unsafe in multithread applications. The asctime_r() and
     gmtime_r() functions are MT-Safe. The ctime_r(),
     localtime_r(), and tzset() functions are MT-Safe in mul-
     tithread applications, as long as no user-defined function
     directly modifies one of the following variables: timezone,
     altzone, daylight, and tzname. These four variables are not
     MT-Safe to access. They are modified by the tzset() function
     in an MT-Safe manner. The mktime(), localtime_r(), and
     ctime_r() functions call tzset().

> Is there solution for this?

Use localtime_r() instead of localtime().

Andreas.



Relevant Pages

  • Re: Life of static variables in ASP.NET 2.0
    ... Dictionary description on MSND does say that iteration operations are not ... thread safe. ... Static data may be loaded in a singleton class. ... until Asp.Net recycles ...
    (microsoft.public.dotnet.framework.aspnet)
  • Manipulating instance var from a static method - thread safe?
    ... I've just realized that static data are not thread safe because they are ... What if a static method is ... the time the method is manipulating it? ...
    (microsoft.public.dotnet.framework.aspnet)