Re: gettimeofday cause crash on Windows

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Asif Naeem <anaeem(dot)it(at)gmail(dot)com>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: gettimeofday cause crash on Windows
Date: 2015-02-13 02:59:49
Message-ID: CAB7nPqSfCEyPZRk40JUKvvOX==WgiDwsP75VMFRT8eRKZ+ak_A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, Feb 13, 2015 at 4:41 AM, Asif Naeem wrote:
> On Thu, Feb 12, 2015 at 10:53 PM, Andres Freund wrote:
>>
>> On 2015-02-12 12:14:03 -0300, Alvaro Herrera wrote:
>> > Asif Naeem wrote:
>> > > Don't you feel gettimeofday() implementation is incomplete in current
>> > > state, Is there any other example of function port in PG that could
>> > > lead to
>> > > crash if its related init_* function is not called earlier ?. As
>> > > mentioned
>> > > by Michael, it seems not enough documented (release notes etc), at
>> > > least it
>> > > need to give warning etc instead of simply crash the related process.
>> > > GetSystemTimeAsFileTime() function is less precise but it is quite
>> > > fast and
>> > > less CPU intensive then GetSystemTimePreciseAsFileTime() function,
>> > > GetSystemTimePreciseAsFileTime() can effect performance of an
>> > > application.
>> > > With the proposed patch, gettimeofday() function is more safe and more
>> > > versatile, a contrib may use it as per its need of precision. Thanks.
>> >
>> > Ideally we would the Precise dance automatically, without requiring the
>> > program to call an initialization function. Otherwise, programs may
>> > never be updated to use Precise rather than the stock function. I guess
>> > this is the reason Andres prefers a crash: to force programs to be
>> > updated to include the initialization step.
>> >
>> > I wonder if it would work to set the function initially to the
>> > initialization function, so that on the first call the Precise version,
>> > if it exists, is detected (or the stock version otherwise) and set as
>> > the function to call for later -- without requiring a jump in every
>> > subsequent execution of gettimeofday(), of course. The initialization
>> > function itself would have to return the value returned by
>> > GetSystemTimePreciseAsFileTime, of course.
>>
>> Yes, that sounds like a good idea.

+1. Excellent idea.

> Superb idea. PFA patch. Please do let me know if I missed something. Thanks.

I looked at your patch and tested it with msvc and it looks good to me.

Note not related to this patch at all: shouldn't we update the
copyright notice on top of this gettimeofday.c btw with some PGDG
stuff?
--
Michael

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Heikki Linnakangas 2015-02-13 13:29:23 Re: postgresql-server exiting abnormally after an OS upgrade
Previous Message Tom Lane 2015-02-13 00:46:46 Re: BUG #12766: Dump/Load of Materialized View with inlined SQL function fails