From owner-freebsd-current@FreeBSD.ORG Mon Apr 25 13:33:07 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 1EFA216A4CE for ; Mon, 25 Apr 2005 13:33:07 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0476343D2F; Mon, 25 Apr 2005 13:33:07 +0000 (GMT) (envelope-from davidxu@freebsd.org) Received: from [127.0.0.1] (davidxu@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j3PDX3Qq084226; Mon, 25 Apr 2005 13:33:05 GMT (envelope-from davidxu@freebsd.org) Message-ID: <426CF18E.5050203@freebsd.org> Date: Mon, 25 Apr 2005 21:33:02 +0800 From: David Xu User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.5) Gecko/20050306 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Mayank Kumar References: <3A5384BC2FBA4C488865F2275A036BFF027C1614@APS-MSG-01.southpacific.corp.microsoft.com> In-Reply-To: <3A5384BC2FBA4C488865F2275A036BFF027C1614@APS-MSG-01.southpacific.corp.microsoft.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit 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:33:07 -0000 Mayank Kumar wrote: >Hi All >Recently I have been looking at few freebsd libc functions and I found >That they were not thread safe. Can one of you please confirm. > >Following functions in freebsd libc are not thread safe:- >1: vsnprintf >2: vsprintf >3: vsscanf > theere are many more. > >Functions like vfprintf are written as follows:- >------------- >int ret; > > FLOCKFILE(fp); > ret = __vfprintf(fp, fmt0, ap); > FUNLOCKFILE(fp); > return (ret); >---------------- >Which ensures that they are thread safe. > >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. > >Thanks and regards >Mayank > vsnprintf and vsprintf use a on stack FILE structure, no other threads can see the structure, it won't be shared with other threads, so lock is not needed. Cheers, David Xu