Implemented isPrimaryThread and callSyncMethod, along with helper syncIfNeeded.