From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id A739BBDDB for ; Sat, 3 Sep 2005 09:05:28 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j8375RN0014071 for ; Sat, 3 Sep 2005 09:05:27 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA20152 for ; Sat, 3 Sep 2005 09:05:27 +0200 (MET DST) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j8375Q0D009341 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Sat, 3 Sep 2005 09:05:27 +0200 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1EBS4X-0004CG-Rs for caml-list@inria.fr; Sat, 03 Sep 2005 09:04:17 +0200 Received: from 0x50a5bb8d.odnxx9.adsl-dhcp.tele.dk ([80.165.187.141]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 03 Sep 2005 09:04:17 +0200 Received: from spam by 0x50a5bb8d.odnxx9.adsl-dhcp.tele.dk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 03 Sep 2005 09:04:17 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Bardur Arantsson Subject: Re: Unix.localtime not threadsafe? Date: Sat, 03 Sep 2005 09:03:08 +0200 Message-ID: References: <891bd339050902103460db1a55@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 0x50a5bb8d.odnxx9.adsl-dhcp.tele.dk User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050803) X-Accept-Language: en-us, en In-Reply-To: <891bd339050902103460db1a55@mail.gmail.com> Sender: news X-Miltered: at nez-perce with ID 43194B37.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 43194B36.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; yaron:01 minsky:01 ocaml:01 runtime:01 ocaml:01 pointer:01 statically:01 struct:01 api:01 sdu:01 ...:98 wrote:01 unix:01 unix:01 glibc:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Yaron Minsky wrote: > I was looking at the Unix.localtime implementation, and it appears to > me that it's not threadsafe. I'm wondering if anyone can confirm. > > First off, the underlying localtime call is definitely not re-entrant. > The tm data structure is shared among all calls, leading to the > possibility of races. What I'm not sure of is whether there can be a > race given the locking of the OCaml runtime. Here's the code from > gmtime.c in the ocaml distribution: I don't think the glibc/Linux localtime() man page explicitly states this, but I expect that it returns a pointer to a *thread-local* statically allocated struct tm... in which case there's no problem. Most other system functions whose API looks non-threadsafe do the same. ('errno' would be the standard example). [--snip--] -- Bardur Arantsson - But don't be reading my mind between 4 and 5. That's Willie's time! Groundskeeper Willie, 'The Simpsons'