Using the Raw Native Interface Previous
Previous
Introduction
Introduction
Next
Next

Synchronization

Native methods marked as being synchronized don't automatically lock\unlock the object so you must do any necessary synchronization on the native side. ObjectMonitorEnter() takes an object monitor, ObjectMonitorExit() leaves it, ObjectMonitorNotify() is analogous to Object.notify() and ObjectMonitorNotifyAll() is analogous to Object.notifyAll(). For example, a typical synchronized method will look like

    long cdecl Some_Java_SynchronizedMethod(struct HSomeJava *phThisUnsafe)
    {
        // Normal GC protection stuff.
        HSomeJava *phThisSafe;
        GCFrame gcf;
        
        GCFramePush(&gcf, &phThisSafe, sizeof(phThisSafe));
        phThisSafe = phThisUnsafe;
        
        ObjectMonitorEnter(phThisSafe);

        // Code here executes synchronised on this object.

        ObjectMonitorExit(phThisSafe);

        GCFramePop(&gcf);
   }


© 1996 Microsoft Corporation. All rights reserved.