Pthread Iissue?

Matthew Dillon dillon at apollo.backplane.com
Thu Aug 7 17:02:43 PDT 2003


    It fails on FreeBSD 4.7.  The -pthread option to cc should be
    setting -D_THREAD_SAFE, but apparently is not.  i.e. if you
    compile the program -pthread -D_THREAD_SAFE it will work.

    I dunno about 4.5, maybe something else is preventing the race
    from occuring.

    It seems to me that gcc should set _THREAD_SAFE when -pthread is
    set, no?

					-Matt
					Matthew Dillon 
					<dillon at xxxxxxxxxxxxx>


:The following program dumps core (works on FreeBSD 4.5).
:
:#include <pthread.h>
:#include <stdio.h>
:
:void *
:thread (void *param)
:{
:   char ch = (char) param;
:   int i;
:   for (i=0; i<4097; i++) {
:     putchar(ch);
:   }
:}
:
:
:int
:main (void)
:{
:   pthread_t tid;
:
:
:   pthread_create (&tid, NULL, thread, (void *)'A');
:   pthread_create (&tid, NULL, thread, (void *)'B');
:
:   pthread_join(tid, NULL);
:
:}
:
:[deleted]
:BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBSegmentation 
:fault (core dumped)
:
:steve at fred threads> gdb thread101 thread101.core
:GNU gdb 4.18 (FreeBSD)
:Copyright 1998 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-unknown-freebsd"...Deprecated bfd_read 
:called at 
:/usr/src/gnu/usr.bin/binutils/gdb/../../../../contrib/gdb/gdb/dbxread.c 
:line 2627 in elfstab_build_psymtabs
:Deprecated bfd_read called at 
:/usr/src/gnu/usr.bin/binutils/gdb/../../../../contrib/gdb/gdb/dbxread.c 
:line 933 in fill_symbuf
:
:Core was generated by `thread101'.
:Program terminated with signal 11, Segmentation fault.
:Reading symbols from /usr/lib/libc_r.so.4...done.
:Reading symbols from /usr/libexec/ld-elf.so.1...done.
:#0  0x280da64f in __swbuf () from /usr/lib/libc_r.so.4
:(gdb) bt full
:#0  0x280da64f in __swbuf () from /usr/lib/libc_r.so.4
:No symbol table info available.
:#1  0x804863e in __sputc (_c=65, _p=0x280fe2f8) at /usr/include/stdio.h:366
:         _c = 65
:         _p = (FILE *) 0x280fe2f8
:#2  0x80485a7 in thread (param=0x41) at thread101.c:12
:         ch = 65 'A'
:         i = 4096
:#3  0x2807f110 in _thread_start () from /usr/lib/libc_r.so.4
:No symbol table info available.
:#4  0x0 in ?? ()
:No symbol table info available.
:(gdb) list 12
:7       thread (void *param)
:8       {
:9         char ch = (char) param;
:10        int i;
:11        for (i=0; i<4097; i++) {
:12          putchar(ch);
:13        }
:14      }
:15
:16
:(gdb)
:
:-- Steve





More information about the Bugs mailing list