Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 May 2005 15:28:21 +0200
From:      Marc Olzheim <marcolz@stack.nl>
To:        freebsd-threads@freebsd.org
Subject:   Re: Floating point exceptions with -pthread
Message-ID:  <20050503132821.GC66132@stack.nl>
In-Reply-To: <20050503132312.GB66132@stack.nl>
References:  <20050503110818.GA66132@stack.nl> <20050503132312.GB66132@stack.nl>

next in thread | previous in thread | raw e-mail | index | archive | help

--jL2BoiuKMElzg3CS
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, May 03, 2005 at 03:23:12PM +0200, Marc Olzheim wrote:
> I've narrowed it down to the following program. The th version crashes
> within seconds, while the non th version has no problems.
> amd64 doesn't have this problem either; it just goes wrong on
> i386/SMP+HT.
> i386/SMP (athlon MP) seems to have no problems either.
>=20
> Am I doing something wrong here ?

Don't know what happened with my attachment... Let's try again.

Btw.: here's a gdb trace:

gdb ~/src/fpu5th fpu5th.60245=20
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain condition=
s.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-marcel-freebsd"...
Core was generated by `fpu5th'.
Program terminated with signal 8, Arithmetic exception.
Reading symbols from /lib/libm.so.3...done.
Loaded symbols for /lib/libm.so.3
Reading symbols from /usr/lib/libpthread.so.1...done.
Loaded symbols for /usr/lib/libpthread.so.1
Reading symbols from /lib/libc.so.5...done.
Loaded symbols for /lib/libc.so.5
Reading symbols from /libexec/ld-elf.so.1...done.
Loaded symbols for /libexec/ld-elf.so.1
#0  0x280ad31b in pthread_testcancel () from /usr/lib/libpthread.so.1
(gdb) info threads
* 4 LWP 100362  0x280ad31b in pthread_testcancel () from /usr/lib/libpthrea=
d.so.1
  3 Thread 3 (sleeping)  0x280a5207 in pthread_mutexattr_init () from /usr/=
lib/libpthread.so.1
  2 Thread 2 (LWP 100512)  0x280ad2fb in pthread_testcancel () from /usr/li=
b/libpthread.so.1
  1 Thread 1 (runnable)  floorf () at /usr/src/lib/msun/i387/s_floorf.S:23
Current language:  auto; currently asm
(gdb) thread 1
[Switching to thread 1 (Thread 1 (runnable))]#0  floorf () at /usr/src/lib/=
msun/i387/s_floorf.S:23
23              flds    8(%ebp);                /* round */
(gdb) up
#1  0x08048794 in calc_thread (arg=3D0x1) at fpu5.c:36
36                              c =3D floorf((float)(1.0 / logf((float)1.0 =
+ (float)i)));
Current language:  auto; currently c
(gdb) p i
$1 =3D 440
(gdb) info registers=20
eax            0x120    288
ecx            0x2e0    736
edx            0x841e   33822
ebx            0x1b8    440
esp            0xbfaedf90       0xbfaedf90
ebp            0xbfaedfb8       0xbfaedfb8
esi            0x1b8    440
edi            0x8053500        134558976
eip            0x8048794        0x8048794
eflags         0x10286  66182
cs             0x1f     31
ss             0x2f     47
ds             0x2f     47
es             0x2f     47
fs             0x2f     47
gs             0xa7     167
(gdb)

The program:

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	fpu
#	fpu/Makefile
#	fpu/fpu5.c
#
echo c - fpu
mkdir -p fpu > /dev/null 2>&1
echo x - fpu/Makefile
sed 's/^X//' >fpu/Makefile << 'END-of-fpu/Makefile'
Xall: fpu5 fpu5th
X
Xfpu5th:	fpu5.c
X	cc -O3 -Wall -W -Werror -g -Wcast-qual -I/usr/local/include -L/usr/local/=
lib -DWITH_THR -fstrict-aliasing -pthread fpu5.c -o fpu5th -lm
X
Xfpu5:	fpu5.c
X	cc -O3 -Wall -W -Werror -g -Wcast-qual -I/usr/local/include -L/usr/local/=
lib -fstrict-aliasing fpu5.c -o fpu5 -lm
END-of-fpu/Makefile
echo x - fpu/fpu5.c
sed 's/^X//' >fpu/fpu5.c << 'END-of-fpu/fpu5.c'
X/* Blame it in Marc Olzheim (Zlo) */
X
X#ifdef		WITH_THR
X#include	<pthread.h>
X#endif		/* WITH_THR */
X
X#include	<err.h>
X#include	<math.h>
X#include	<stdio.h>
X#include	<stdlib.h>
X#include	<sysexits.h>
X#include	<unistd.h>
X
Xvoid *
Xcalc_thread(void *arg)
X{
X	long		i;
X	unsigned char	c;
X
X	i =3D (long)arg + 1;
X
X	for (;;)
X	{
X		i =3D (i + 1) % 736;
X		if (i > 0)
X		{
X			/* ln(2.0) =3D~ 0.69 */
X			if (logf((float)1.0 + (float)i) < (float)0.65)
X			{
X				/* Never happens */
X				printf("\n\n\n\ni: %ld\n\n\n\n", i);
X				fflush(NULL);
X			}
X
X			/* Then why does _this_ go wrong ? */
X			c =3D floorf((float)(1.0 / logf((float)1.0 + (float)i)));
X
X			if (c > 1)	/* Never true, just to use c. */
X				printf("\r%hhu", c);
X		}
X	}
X
X	/* NOTREACHED */
X	return NULL;
X}
X
Xint
Xmain(int argc, char *argv[])
X{
X#ifdef		WITH_THR
X	pthread_t	thread;
X#endif		/* WITH_THR */
X
X	if (1 !=3D argc)
X	{
X		fprintf(stderr, "Usage: %s\n", argv[0]);
X		return(EX_USAGE);
X	}
X
X#ifdef		WITH_THR
X	if (pthread_create(&thread , NULL, calc_thread, (void *)1L))
X		err(1, "pthread_create()");
X#else		/* ! WITH_THR */
X	(void)calc_thread((void *)1L);
X#endif		/* ! WITH_THR */
X
X	for (;;)
X		sleep(60);
X
X	return(EX_OK);
X}
END-of-fpu/fpu5.c
exit


--jL2BoiuKMElzg3CS
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (FreeBSD)

iD8DBQFCd3x1ezjnobFOgrERAlXJAJ9YAJJbvfzrcg6kDWlFMnO0PEbF8wCeKD2Q
dAH9kkghmNIFK3Sg7Vw5pXw=
=uutq
-----END PGP SIGNATURE-----

--jL2BoiuKMElzg3CS--



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