JNI program hangs unless mutex locks are used.
Application uses 5.0 C and 1.2.1_04 java
Customer info
"
I also attached a tarball to this mail with the source of both the C and
Java test program. The compile and build steps are:
1) gzip -dc sun.tar.gz | tar -xvf -
2) cd sun
3) make
4) javac javatest.java
This builds the C test program, the JNI shared library, and the Java test
program.
To run the C test program, type './ctest'. To run the Java test program,
type
'export CLASSPATH=.; export LD_LIBRARY_PATH=.;java javatest'.
The C program runs to completion everytime. The Java test program
occasionally
hangs.
I'll give you some information about the program, so you know what it is
trying to do. Threads.c contains the threading stuff. One server thread
gets created. There is one resource (stdout) that needs to be shared between
the clients. Clients put requests for the resource in a list. The server
thread handles 1 request per time. When it handles a request it hands over
stdout to the client thread. When the client thread is finished with it, it
hands it back to the server by calling provide(). This makes the resource
available for the server thread again. It can then process the next request.
Access to the request list, and the resource is handled by a semaphore
structure (a mutex and a condition variable). The code is commented and
should explain what is happening.
"
Application uses 5.0 C and 1.2.1_04 java
Customer info
"
I also attached a tarball to this mail with the source of both the C and
Java test program. The compile and build steps are:
1) gzip -dc sun.tar.gz | tar -xvf -
2) cd sun
3) make
4) javac javatest.java
This builds the C test program, the JNI shared library, and the Java test
program.
To run the C test program, type './ctest'. To run the Java test program,
type
'export CLASSPATH=.; export LD_LIBRARY_PATH=.;java javatest'.
The C program runs to completion everytime. The Java test program
occasionally
hangs.
I'll give you some information about the program, so you know what it is
trying to do. Threads.c contains the threading stuff. One server thread
gets created. There is one resource (stdout) that needs to be shared between
the clients. Clients put requests for the resource in a list. The server
thread handles 1 request per time. When it handles a request it hands over
stdout to the client thread. When the client thread is finished with it, it
hands it back to the server by calling provide(). This makes the resource
available for the server thread again. It can then process the next request.
Access to the request list, and the resource is handled by a semaphore
structure (a mutex and a condition variable). The code is commented and
should explain what is happening.
"