Date: Mon, 25 Apr 2005 21:33:02 +0800 From: David Xu <davidxu@freebsd.org> To: Mayank Kumar <mayank@microsoft.com> Cc: freebsd-current@freebsd.org Subject: Re: Query regarding thread safety of few libc stdio functions Message-ID: <426CF18E.5050203@freebsd.org> In-Reply-To: <3A5384BC2FBA4C488865F2275A036BFF027C1614@APS-MSG-01.southpacific.corp.microsoft.com> References: <3A5384BC2FBA4C488865F2275A036BFF027C1614@APS-MSG-01.southpacific.corp.microsoft.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?426CF18E.5050203>