title: Realm deadlock condition
body: <p>Actually in my application i have notification service extension from their updating my realm db which is in shared group folder and main application also write on same.</p>
  
  <p>Some time my app stops working due to deadlock arises and app always fails to write. App have db write code in main app initialisation process. so only phone reboot take user out of the problem.</p>
  
  <p>Here is my notification extension code for writing</p>
  
  <pre><code>func updateInTime(userId: Int) {
  
          let container = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.****")
          let realmURL = container!.appendingPathComponent("default.realm")
          do {
              let config = Realm.Configuration(
                  fileURL: realmURL,
                  schemaVersion: schemaVersion)
              Realm.Configuration.defaultConfiguration = config
              updateUserTime(userId: userId)
          }
      }
  
  
      func updateUserTime(userId: Int) {
         do {
              let realm = try Realm()
              let predicate = NSPredicate(format: "userID == %d", userId)
              let inTimes = realm.objects(UserInTime.self).filter(predicate)
              if let inTime = inTimes.first {
                  try realm.write {
                      inTime.inRadiusTime = Date()
                  }
  
              }
          } catch {
              //Logger.KWLogDebug("Failed to access the Realm database")
          }
          do {
              let realm = try Realm()
              let inTime = UserInTime()
              inTime.userID = userId
              inTime.inRadiusTime = Date()
  
              try realm.write {
                  realm.addOrUpdate(inTime)
              }
          } catch {
              print(error)
          }
  
      }
  </code></pre>
  
  <p>updateInTime func calls from didReceive(_ request: contentHandler:)</p>
  
  <p>Realm version : </p>
  
  <blockquote>
    <p>3.10.0</p>
  </blockquote>
  
  <p>Here is crash log info from device</p>
  
  <pre><code>**Exception Type:  EXC_CRASH (SIGKILL)
  Exception Codes: 0x0000000000000000, 0x0000000000000000
  Exception Note:  EXC_CORPSE_NOTIFY
  Termination Reason: Namespace SPRINGBOARD, Code 0x8badf00d
  Termination Description: SPRINGBOARD, scene-create watchdog transgression: application&lt;com.myapp&gt;:9023 exhausted real (wall clock) time allowance of 29.25 seconds | ProcessVisibility: Background | ProcessState: Running | WatchdogEvent: scene-create | WatchdogVisibility: Background | WatchdogCPUStatistics: ( | "Elapsed total CPU time (seconds): 52.630 (user 52.630, system 0.000), 29% CPU", | "Elapsed application CPU time (seconds): 0.725, 0% CPU" | )
  Triggered by Thread:  0
  
  Thread 0 name:  Dispatch queue: com.apple.main-thread
  Thread 0 Crashed:
  0   libsystem_kernel.dylib          0x00000001b7eae27c 0x1b7e87000 + 160380
  1   Realm                           0x00000001084644e4 realm::util::File::lock+ 2802916 (bool, bool) + 64
  2   Realm                           0x0000000108396800 realm::SharedGroup::do_begin_write+ 1959936 () + 88
  3   Realm                           0x00000001082e5c68 realm::_impl::transaction::begin(std::__1::unique_ptr&lt;realm::SharedGroup, std::__1::default_delete&lt;realm::SharedGroup&gt; &gt; const&amp;, realm::BindingContext*, realm::_impl::NotifierPackage&amp;) + 1236072 (group_shared.hpp:986)
  4   Realm                           0x00000001081fc568 realm::_impl::RealmCoordinator::promote_to_write(realm::Realm&amp;) + 279912 (realm_coordinator.cpp:856)
  5   Realm                           0x00000001082c04f4 realm::Realm::begin_transaction() + 1082612 (shared_realm.cpp:667)
  6   Realm                           0x000000010828f43c -[RLMRealm beginWriteTransaction] + 881724 (RLMRealm.mm:577)
  7   myapp-ios                       0x00000001050d0630 specialized static UserSettings.update+ 1082928 (_:) + 460**
  </code></pre>
  
  <p>How can i resolve this issue.</p>