JNI Multi-threaded Access Problems

Hey All,

Ever since cocos2d-x v2.2.2 I’ve had the problem of not being able to access the JNI asynchronously.
The best way to reproduce this is:

  1. spawn a new thread with pthread()
  2. call getWriteablePath() from that thread - note getWriteablePath uses the JNI
    Result you get is a crash in JniHelper.cpp line 217.

In v2.2.2, somebody added pthread_setspecific for automatic detachment of threads from the JNI upon thread completion. The problem seems to be that this didn’t take into account multiple threads… i think. I’m not very familiar with the use of pthread_setspecific but that’s what it looks like is happening.

Removing pthread_setspecific usage from JniHelper.cpp prevents the crashes, but the original problem of leaking threads returns.

Here’s the bug report I filed:
http://cocos2d-x.org/issues/3993
Here’s a related forum post:
http://cocos2d-x.org/forums/6/topics/44112?r=44650

Thanks