Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use JNI equivalent of synchronization to guarantee native data accessed by two threads are synched:</p> <pre><code>//before read/writing shared data (*env)-&gt;MonitorEnter(obj); ... /* synchronized block */ //after read/writing shared data (*env)-&gt;MonitorExit(obj); </code></pre> <p>You can find more info in this <a href="http://www.ibm.com/developerworks/java/tutorials/j-jni/section4.html" rel="nofollow">IBM article</a>.</p> <p><strong>Edit:</strong> After a bit more digging, it turns out that how C code should be kept synchronized is VM-implementation dependent (see section 2.1: <a href="http://www.hdfgroup.org/hdf-java-html/JNI/" rel="nofollow">http://www.hdfgroup.org/hdf-java-html/JNI/</a>). The scary part is this: </p> <blockquote> <p>...and in most cases there is no way to know what the C code must do.</p> </blockquote> <p>Unfortunately I can't find info on how Android specifically handles this, or whether it's handled consistently between Android versions.</p> <p>However, another interesting info is provided by Android dev site (<a href="http://developer.android.com/training/articles/smp.html" rel="nofollow">http://developer.android.com/training/articles/smp.html</a>) which indicated that ARM CPUs provides weak memory consistency, so this may be the default behavior for C code.</p> <p>Basically the issue comes down to: <em>Whether c data would be synchronized when thread access is synchronized in Java</em>. Since link 1 (<a href="http://www.hdfgroup.org/hdf-java-html/JNI/" rel="nofollow">http://www.hdfgroup.org/hdf-java-html/JNI/</a>) doesn't give us an straight answer on this, and link 2 (<a href="http://developer.android.com/training/articles/smp.html" rel="nofollow">http://developer.android.com/training/articles/smp.html</a>) indicate that ARM CPUs provides weak memory consistency, doing a monitor call in C code again seem to be the safer bet.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload