Subject: BUG: Timezone failures with threads under Cygwin 1.5.25
From: "Jerry D. Hedden" <[email-masked]>
To: [email-masked]
Cc: pp <[email-masked]>
Date: Mon, 10 Dec 2007 17:00:52 -0500
List-Id: <cygwin.cygwin.com>

(CC'ed to perl5-porters for reference.)

The Perl test suite contains a file
(perl-current/ext/threads/t/libc.t) that exercises the
'localtime' call under threads.  Here's the main code:

    my $i = 10;
    my $y = 20000;

    my %localtime;
    for (1..$i) {
        $localtime{$_} = localtime($_);
    };

    my @threads;
    for (1..$i) {
        $threads[$_] = threads->create(sub {
                            my $arg = shift;
                            my $localtime = $localtime{$arg};
                            my $error = 0;
                            for (1..$y) {
                                my $lt = localtime($arg);
                                if ($localtime ne $lt) {
                                    $error++;
                                }
                            }
                            return $error;
                        }, $_);
    }

    for (1..$i) {
        is($threads[$_]->join(), 0, 'localtime() thread-safe');
    }

This runs 10 threads that call 'localtime' 20,000 times
each.

Under 1.5.24, this test always passes.  Under 1.5.25, it is
now frequently failing.  If I add a debugging call in the
central most loop:

            print("got: $lt  exp: $localtime\n");

I get the following as typical of the problem:

    5 perl-current > ./perl -Ilib ext/threads/t/libc.t
    1..11
    ok 1 - use threads
    got: Wed Dec 31 20:00:08 1969  exp: Wed Dec 31 19:00:08 1969
    got: Wed Dec 31 20:00:07 1969  exp: Wed Dec 31 19:00:07 1969
    got: Wed Dec 31 20:00:06 1969  exp: Wed Dec 31 19:00:06 1969
    got: Wed Dec 31 20:00:08 1969  exp: Wed Dec 31 19:00:08 1969
    got: Wed Dec 31 20:00:07 1969  exp: Wed Dec 31 19:00:07 1969
    got: Wed Dec 31 20:00:06 1969  exp: Wed Dec 31 19:00:06 1969
    got: Wed Dec 31 20:00:10 1969  exp: Wed Dec 31 19:00:10 1969
    ok 2 - localtime() thread-safe
    ok 3 - localtime() thread-safe
    ok 4 - localtime() thread-safe
    ok 5 - localtime() thread-safe
    ok 6 - localtime() thread-safe
    not ok 7 - localtime() thread-safe
    # Failed at ext/threads/t/libc.t line 52
    #      got '2'
    # expected '0'
    not ok 8 - localtime() thread-safe
    # Failed at ext/threads/t/libc.t line 52
    #      got '2'
    # expected '0'
    not ok 9 - localtime() thread-safe
    # Failed at ext/threads/t/libc.t line 52
    #      got '2'
    # expected '0'
    ok 10 - localtime() thread-safe
    not ok 11 - localtime() thread-safe
    # Failed at ext/threads/t/libc.t line 52
    #      got '1'
    # expected '0'

This shows a 1 hour difference between the expected and
actual results - which looks like a timezone issue.

As the changes for 1.5.25 include numerous references to
timezone handling changes, I suspect there may be some
re-entrancy bug in those changes.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/