[Bug libgcj/14225] New: when using gcj cni calls within a pthread i get a segfault

sturmf at in dot tum dot de gcc-bugzilla@gcc.gnu.org
Fri Feb 20 11:59:00 GMT 2004


I have this small testprogram which when executed returns a segfault.
The problem seems to be when I start using cni calls in pthreads.
I already searched the web for any obvious mistakes I made.

The gcc version is:
gcc (GCC) 3.3.2 20031218 (Gentoo Linux 3.3.2-r5, propolice-3.3-7)

gcc -v results in:
Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/specs
Configured with: /var/tmp/portage/gcc-3.3.2-r5/work/gcc-3.3.2/configure
--prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/3.3
--includedir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/include
--datadir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3
--mandir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3/man
--infodir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3/info --enable-shared
--host=i686-pc-linux-gnu --target=i686-pc-linux-gnu --with-system-zlib
--enable-languages=c,c++,f77,objc,java --enable-threads=posix --enable-long-long
--disable-checking --enable-cstdio=stdio --enable-clocale=generic
--enable-__cxa_atexit --enable-version-specific-runtime-libs
--with-gxx-include-dir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/include/g++-v3
--with-local-prefix=/usr/local --enable-shared --enable-nls
--without-included-gettext --x-includes=/usr/X11R6/include
--x-libraries=/usr/X11R6/lib --enable-interpreter --enable-java-awt=xlib
--with-x --disable-multilib
Thread model: posix
gcc version 3.3.2 20031218 (Gentoo Linux 3.3.2-r5, propolice-3.3-7)

To build the program I used:
g++ -Wall -g -o crashme crashme.cpp -L/usr/lib -lpthread -lgcj

The compiler output:
It did not produce any warnings/errors

The program (there was no button to attach a file so here it is inline)

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
                                                                                
#include <gcj/cni.h>
#include <java/lang/System.h>
#include <java/io/PrintStream.h>
#include <java/lang/Throwable.h>
                                                                                
                                                                                
using namespace java::lang;
                                                                                
void *testThread(void *threadid) {
                                                                                
        //JvAttachCurrentThread(NULL, NULL); Does not work would crash immediately
                                                                                
        // Here should now be some cni calls
        String *message = JvNewStringLatin1("Hello from C++");
        JvInitClass(&System::class$);
        System::out->println(message);
                                                                                
        while (1) {
                std::cout << "in thread"<< std::endl;
        }
}
                                                                                
                                                                               
                                                                         
int main(int argc, char **argv)
{
        try
        {
                JvCreateJavaVM(NULL);
                // attach current thread to java. should have no sideeffects if
already attached
                JvAttachCurrentThread(NULL, NULL);
        }
        catch (java::lang::Throwable *t)
        {
                throw t;
        }
                                                                                
        pthread_t threads[1];
        int rc;
                                                                                
        // Now create the thread
        rc = pthread_create(&threads[0], NULL, testThread, (void *)0);
        if (rc){
                printf("ERROR; return code from pthread_create() is %d\n", rc);
                exit(-1);
        }
                                                                                
        while (1) {
                sleep(10);
        }
}

Hope this helps to find the bug!

Thanks a lot, Fabian

-- 
           Summary: when using gcj cni calls within a pthread i get a
                    segfault
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: libgcj
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sturmf at in dot tum dot de
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14225



More information about the Gcc-bugs mailing list