This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: GCJ + Roguewave Threads?
- From: Johann Hibschman <johannh at gmail dot com>
- To: Bryce McKinlay <mckinlay at redhat dot com>
- Cc: java at gcc dot gnu dot org
- Date: Fri, 11 Feb 2005 19:37:15 -0500
- Subject: Re: GCJ + Roguewave Threads?
- References: <4b82d65b05021018375719bf18@mail.gmail.com> <420CF999.4090902@redhat.com>
- Reply-to: Johann Hibschman <johannh at gmail dot com>
On Fri, 11 Feb 2005 13:29:45 -0500, Bryce McKinlay <mckinlay@redhat.com> wrote:
> >My hair-brained scheme for tomorrow is to see if I can launch a
> >proper, GC-registered pthread from the main thread, and then use that
> >thread for all subsequent gcj work, leaving the Rogue Wave threads to
> >do their dirty business in the original thread.
> >
> Seems reasonable - just be sure to synchronize the threads correctly if
> you take this route.
Well, I can't seem to get it to work. After I initialize the JVM, all
subsequent calls to pthread_exit(NULL) simply hang.
I'm still using 3.2.3-42, which may account for some of the problems;
I'll keep working on it.
My basic code runs as follows:
#include <iostream>
#define LINUX_THREADS 1
#include <gc.h>
#include <gcj/cni.h>
using namespace std;
namespace
{
static void* doTest2(void *threadId)
{
std::cout << "[thr2] Hello, world! Now calling pthread_exit."
<< std::endl;
pthread_exit(NULL);
}
}
int main(int argc, char** argv)
{
std::cout << "[main] Argc = " << argc << std::endl;
std::cout << "[main] CONSTRUCTING THE JVM!!!" << std::endl;
JvCreateJavaVM(NULL);
std::cout << "[main] Done constructing the jvm." << std::endl;
JvAttachCurrentThread(NULL, NULL);
std::cout << "[main] Done attaching the thread." << std::endl;
pthread_t thread;
int rc;
rc = GC_pthread_create(&thread, NULL, doTest2, NULL);
if (rc)
{
std::cout << "[main] ERROR: return code = " << rc << std::endl;
}
std::cout << "[main] About to detach thread" << std::endl;
JvDetachCurrentThread();
std::cout << "[main] About to call pthread_exit" << std::endl;
pthread_exit(NULL);
std::cout << "[main] About to exit" << std::endl;
return 0;
}
When I run this, I see:
[main] Argc = 1
[main] CONSTRUCTING THE JVM!!!
[main] Done constructing the jvm.
[main] Done attaching the thread.
[thr2] Hello, world! Now calling pthread_exit.
[main] About to detach thread
[main] About to call pthread_exit
Am I doing something obviously wrong here? I'm not even trying to run
anything in the JVM; I just want to use a thread at the same time, as
a first step.
Thanks,
Johann