Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Oct 2002 12:54:47 +0100
From:      "Peter Edwards" <pmedwards@eircom.net>
To:        current@freebsd.org
Subject:   Floating point problems
Message-ID:  <20021024115918.057A443E65@mx1.FreeBSD.org>

next in thread | raw e-mail | index | archive | help
Hi,
There was some discussion about issues with interactions between the floating 
point context and signal handling in a thread a week or so ago, and a suggestion 
that someone try and get a simple test that would fail. I was surprised how
easy it was: The following program just spins calculating the value of 6.0 / 
3.0, and traps SIGINT.

If you run it on -current (as of a few hours ago), 99% of the time, hitting 
ctl-C will cause the program to exit with an error. A 4.5 kernel never causes 
any problems.

I'm pretty sure this is what's causing the stalls and crashes in X. I've taken
stack traces of crashes, and from "spinning" processes, and I can spot NaNs on
the stack that shouldn't be there, etc.

I just thought it might be useful to send this, to firmly take the blame
away from the X server, and give someone a way of reproducing the bug.

fptest.c:

#include <math.h>
#include <stdio.h>
#include <signal.h>
#include <assert.h>


int count = 0;
void sigint(int sig)
{
    write(2, "INT\n", 4);
    count++;
}

int
main(int argc, char **argv)
{
    double x = 6.0;
    double y = 3.0;
    double d;
    double err;
    struct sigaction sa;

    sa.sa_handler = sigint;
    sa.sa_flags = 0;
    sigemptyset(&sa.sa_mask);
    sigaction(SIGINT, &sa, 0);

    while (count < 30) {
        d = x / y;
        err = 2.0 - d;
        if (err != 0.0) {
            fprintf(stderr, "err %f!\n", err);
            exit(-1);
        }
    }
}


-- 
Peter Edwards.


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021024115918.057A443E65>