Re: [Mingw-users] Porting localtime_r and gmtime_r
- Date: Tue, 05 Feb 2008 10:47:57 +0800
- From: JonY <10walls@xxxxxxxxx>
- Subject: Re: [Mingw-users] Porting localtime_r and gmtime_r
Brian Dessent wrote:
> JonY wrote:
>
>> Are there any immediate problems with it? If yes, please advice.
>
> No, that won't work. Well, it might work for a single threaded app but
> it is certainly not correct. The reason that you need a re-entrant (_r)
> version of these functions is that the original ones use a static
> buffer. This means that if two or more threads are in contention the
> buffer can change between calls. In other words, what you have is no
> good because the value of the buffer can change before it has been
> memcpy()'d to result because there is only one static buffer shared by
> all callers.
>
> Brian
>
Good point, I suppose copying it to malloc'ed location immediately won't
be safe too, but I did find this message suggesting win32 localtime is
thread safe.
http://sources.redhat.com/ml/pthreads-win32/2005/msg00011.html
Thanks for the quick reply.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users