From owner-freebsd-current@FreeBSD.ORG Mon Apr 25 13:39:58 2005 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DD9E216A4CE for ; Mon, 25 Apr 2005 13:39:58 +0000 (GMT) Received: from arginine.spc.org (arginine.spc.org [83.167.185.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2C1A443D1D for ; Mon, 25 Apr 2005 13:39:58 +0000 (GMT) (envelope-from bms@spc.org) Received: from localhost (localhost [127.0.0.1]) by arginine.spc.org (Postfix) with ESMTP id 046BA65319; Mon, 25 Apr 2005 14:39:15 +0100 (BST) Received: from arginine.spc.org ([127.0.0.1]) by localhost (arginine.spc.org [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 88296-01-7; Mon, 25 Apr 2005 14:39:14 +0100 (BST) Received: from empiric.dek.spc.org (host81-134-90-164.in-addr.btopenworld.com [81.134.90.164]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by arginine.spc.org (Postfix) with ESMTP id 19E076530A; Mon, 25 Apr 2005 14:39:10 +0100 (BST) Received: by empiric.dek.spc.org (Postfix, from userid 1001) id 48BDC64CF; Mon, 25 Apr 2005 14:39:51 +0100 (BST) Date: Mon, 25 Apr 2005 14:39:51 +0100 From: Bruce M Simpson To: Mayank Kumar Message-ID: <20050425133951.GC769@empiric.icir.org> Mail-Followup-To: Mayank Kumar , freebsd-current@freebsd.org References: <3A5384BC2FBA4C488865F2275A036BFF027C1614@APS-MSG-01.southpacific.corp.microsoft.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="VrqPEDrXMn8OVzN4" Content-Disposition: inline In-Reply-To: <3A5384BC2FBA4C488865F2275A036BFF027C1614@APS-MSG-01.southpacific.corp.microsoft.com> cc: freebsd-current@freebsd.org Subject: Re: Query regarding thread safety of few libc stdio functions X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Apr 2005 13:39:59 -0000 --VrqPEDrXMn8OVzN4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, On Mon, Apr 25, 2005 at 09:19:12PM +0800, Mayank Kumar wrote: > Why is the same case not followed for eg with vsnprintf or vsprintf > Vsnprintf calls directly __vfprintf which is not thread safe. Hence > How is there thready safey guranteed. Any help on this front > Would be helpful. 1) Thread safety/locking for the destination buffer is the calling program's responsibility -- the vsprintf() function could have no knowledge of this anyway. 2) In any event __vfprintf() references a file handle. For the vsprintf() case it looks like this is faked up. File handles are global, again, thread safety for C library file handles hasn't been specified by many iterations of the relevant standards (don't quote me on this, though, I'm no standards guru). 3) The __vfprintf() function doesn't appear to modify global data or use any data other than what's in its own scope. Whilst two variables are declared static it doesn't look like they are overwritten. The INITEXTRA() macro appears to iniitalize the pthread mutex used by the library functions to a default value. In any event the mutex should be unnecessary because of 1) above. So in short I think it's thread safe as long as your program performs the necessary locking around shared buffers, which is not an issue which libc will solve for you anyway. This is much the same situation as when working with MSVCRT.DLL (again, something I've had to deal with quite a bit lately at my dayjob). Regards, BMS --VrqPEDrXMn8OVzN4 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Comment: '' iD8DBQFCbPMmueUpAYYNtTsRAqjkAKCkdvZ6uiW3UsWiUT1ZQDlLzHvcnQCfdGaw QWiCfYmQsmtR0KSj/EIahyE= =si/N -----END PGP SIGNATURE----- --VrqPEDrXMn8OVzN4--