Simultaneous accesses to 0x1c0a7f0f8, but modification requires exclusive access error on Xcode 9 beta 4

后端 未结 11 1822
孤城傲影
孤城傲影 2020-11-29 05:15

my project uses both Objective-C and Swift code. When a user logs in, it calls a set of apis for user preference, I have a DataCoordinator.swift class which schedules the AP

相关标签:
11条回答
  • 2020-11-29 05:32

    In my case, I changed the table height during process of build the project. At that time my device was connected with network. I deleted the derived data and it resolved the issue for me.

    0 讨论(0)
  • 2020-11-29 05:38

    I think this 'bug' may be a Swift 4 'feature', specifically something they call 'Exclusive access to Memory'.

    Check out this WWDC video. Around the 50 minute mark, the long-haired speaker explains it.

    https://developer.apple.com/videos/play/wwdc2017/402/?time=233

    You could try turning the thread sanitizer off in your scheme settings if you're happy to ignore it. However, the debugger is trying to tell you about a subtle threading issue so it's probably a better use of your time to try to figure out why you've got something writing to your array at the same time it's being read from.

    0 讨论(0)
  • 2020-11-29 05:38

    This was happening for me when, when I was modifying the predicate as per search query and also reloading the table so its sort of reentry (access) to the same class object code. Please check my stack trace, its setting the 'searchPhrase' and from DB worker again triggering the table reload which in-turn comes back to DB worker again (for Item count. after reloadData).

    0    libswiftCore.dylib                 0x000000010a325590 swift_beginAccess + 568
    1    Groupe                             0x00000001063d5cf0 SCPickUsersInteractor.dbWorker.getter + 59
    2    Groupe                             0x00000001063d5830 SCPickUsersInteractor.count.getter + 58
    3    Groupe                             0x00000001063d8550 protocol witness for SCPickUsersInteractorProtocol.count.getter in conformance SCPickUsersInteractor + 14
    4    Groupe                             0x0000000105a340d0 SCPickUsersViewController.tableView(_:numberOfRowsInSection:) + 278
    5    Groupe                             0x0000000105a34280 @objc SCPickUsersViewController.tableView(_:numberOfRowsInSection:) + 76
    6    UIKitCore                          0x00007fff482a3537 -[UITableView _numberOfRowsInSection:] + 62
    7    UIKitCore                          0x00007fff482b3c42 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 1938
    8    UIKitCore                          0x00007fff482b85cd -[UITableViewRowData numberOfRows] + 67
    9    UIKitCore                          0x00007fff4827362d -[UITableView noteNumberOfRowsChanged] + 117
    10   UIKitCore                          0x00007fff48271b8b -[UITableView reloadData] + 1426
    11   Groupe                             0x0000000105a35890 SCPickUsersViewController.reloadTableView() + 152
    12   Groupe                             0x0000000105a37060 protocol witness for SCListUpdatesProtocol.reloadTableView() in conformance SCPickUsersViewController + 9
    13   Groupe                             0x00000001068a14f0 SCPickUsersPresenter.reloadTableView() + 158
    14   Groupe                             0x00000001068a2350 protocol witness for SCListUpdatesProtocol.reloadTableView() in conformance SCPickUsersPresenter + 17
    15   Groupe                             0x0000000105a8bc90 SCPickUsersDBWorker.searchPhrase.didset + 911
    16   Groupe                             0x0000000105a8c0e0 SCPickUsersDBWorker.searchPhrase.setter + 356
    17   Groupe                             0x0000000105a8ffb0 protocol witness for SCFRCProtocol.searchPhrase.setter in conformance SCPickUsersDBWorker + 37
    18   Groupe                             0x00000001063d6500 SCPickUsersInteractor.searchPhrase.setter + 274
    19   Groupe                             0x00000001063d8630 protocol witness for SCPickUsersInteractorProtocol.searchPhrase.setter in conformance SCPickUsersInteractor + 17
    20   Groupe                             0x0000000105a34eb0 SCPickUsersViewController.searchBar(_:textDidChange:) + 322
    21   Groupe                             0x0000000105a35020 @objc SCPickUsersViewController.searchBar(_:textDidChange:) + 105
    

    Solution worked for me: Called 'reloadData' from DB worker class after few milli seconds or half a second.

    0 讨论(0)
  • 2020-11-29 05:42

    Under the target's Build Settings. Select No Enforcement for Exclusive Access to Memory from Swift Compiler - Code Generation

    0 讨论(0)
  • 2020-11-29 05:43

    In Swift 5.0, this will be the default behavior when running your application in Release mode. Before 5.0 (Swift 4.2.1 as of today and lower) this behavior is only running when in Debug mode.

    Your application will fail in release mode if you ignored this error.

    Consider this example:

    func modifyTwice(_ value: inout Int, by modifier: (inout Int) -> ()) {
      modifier(&value)
      modifier(&value)
    }
    
    func testCount() {
      var count = 1
      modifyTwice(&count) { $0 += count }
      print(count)
    }
    

    What is the value of count, when the print(count) line is printed? Well I don't know either and the compiler gives unpredicatable results when you run this code. This isn't allowed in Swift 4.0 in debug mode and in Swift 5.0 it crashes even in runtime.

    Source: https://swift.org/blog/swift-5-exclusivity/

    0 讨论(0)
  • 2020-11-29 05:44

    In my case, Swift 4 actually uncovered a kind of bug that I wouldn't have noticed until I started calling a function from more than one place. My function was passed an inout global array and it was referencing both that parameter and the global name. When I changed the function to reference only the parameter, the "simultaneous access" error went away.

    0 讨论(0)
提交回复
热议问题