jni asynchronous callback: program dies after 13100 calls
843829Mar 13 2008 — edited Mar 18 2008Hi Everyone,
I am trying to use jni from within Google Web Toolkit to monitor some special hardware. The hardware vendor supplies a dynamic linking library (dll) and I am using a JNI C wrapper to call library functions from within my java code. Everything works just fine, there is only one very special problem. The library uses one callback function to dispatch hardware events i.e. I supply the address of a c function ---named Callback in the following--- with a certain signature. According to the manual: after registering the function the dll starts a new thread and calls that function consecutively from the new thread. It is not time critical, if I miss something its not a big deal. My thought was to have the Callback function write the events into a circular buffer and read it from my C-wrapper code.
Everything works fine for the first about 13100 calls of the Callback function. Then the program is killed and I do not get an error message at all. The wired thing is it is killed after the same number of calls each time no matter how big the circular buffer is, no matter what the frequency of events is. It is even killed after the same number of calls if the callback function has an empty body.
Stuff I tried: If I do the same from a plain C or C++ program the code works without problems. The Callback function can have an empty body ---it does nothing apart from getting called--- the program still dies. I tried to call AttachCurrentThread the first time the Callback function is called. I tried to put the callback function in its own object file to make sure it is plain C calling convention.
Now I am at a complete loss. It sounds like some Buffer fills up, but I have now idea which one and why. Any suggestions, comments, directions are greatly appreciated. I can supply example code --- but an empty callback function is not too impressive :(
void MyCallback(long V, long M, long l, double D, long Result )
{
}
Thanks
Peter