Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaNativeFoundation.framework/Headers/JNFRunLoop.h

Native locks are evil

  • Using pthread_lock() or NSLock will almost always get you in trouble
    • These locks are not recursive like Java locks are
  • Using @synchronized in ObjC is slow
    • Since the lock storage is not in the object header itself (like it is in Java) a side-table must be consulted
  • If you need to serialize execution of a task in native, use a serial GCD dispatch_queue
    • They are quite cheap to use in the uncontended case
  • Avoid doing any work that will call back up into Java while holding a native lock or performing on a serial queue
    • It is very easy to deadlock with a Java semaphore and not realize it
      • These deadlocks are almost impossible to debug