Floating point exceptions with -pthread
Marc Olzheim
marcolz at stack.nl
Tue May 3 06:28:29 PDT 2005
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.
>
> 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
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 conditions.
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/libpthread.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/lib/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=0x1) at fpu5.c:36
36 c = floorf((float)(1.0 / logf((float)1.0 + (float)i)));
Current language: auto; currently c
(gdb) p i
$1 = 440
(gdb) info registers
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 = (long)arg + 1;
X
X for (;;)
X {
X i = (i + 1) % 736;
X if (i > 0)
X {
X /* ln(2.0) =~ 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 = 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 != 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-threads/attachments/20050503/748cc200/attachment.bin
More information about the freebsd-threads
mailing list