{"action":"created","issue":{"url":"https://api.github.com/repos/uchicago-mobi/2016-Winter-Forum/issues/176","repository_url":"https://api.github.com/repos/uchicago-mobi/2016-Winter-Forum","labels_url":"https://api.github.com/repos/uchicago-mobi/2016-Winter-Forum/issues/176/labels{/name}","comments_url":"https://api.github.com/repos/uchicago-mobi/2016-Winter-Forum/issues/176/comments","events_url":"https://api.github.com/repos/uchicago-mobi/2016-Winter-Forum/issues/176/events","html_url":"https://github.com/uchicago-mobi/2016-Winter-Forum/issues/176","id":135312485,"number":176,"title":"URGENT: Guaranteeing critical sections execute sequentially","user":{"login":"manglano","id":6961916,"avatar_url":"https://avatars.githubusercontent.com/u/6961916?v=3","gravatar_id":"","url":"https://api.github.com/users/manglano","html_url":"https://github.com/manglano","followers_url":"https://api.github.com/users/manglano/followers","following_url":"https://api.github.com/users/manglano/following{/other_user}","gists_url":"https://api.github.com/users/manglano/gists{/gist_id}","starred_url":"https://api.github.com/users/manglano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manglano/subscriptions","organizations_url":"https://api.github.com/users/manglano/orgs","repos_url":"https://api.github.com/users/manglano/repos","events_url":"https://api.github.com/users/manglano/events{/privacy}","received_events_url":"https://api.github.com/users/manglano/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-02-22T04:28:18Z","updated_at":"2016-02-22T18:04:18Z","closed_at":null,"body":"I am trying to ensure data loads automatically at startup and when a search term is specified; I create a concurrency thread and queue instructions using a dispatch_sync critical section for that purpose:\r\n\r\n`        dispatch_sync(concurrentNetworkQueue){\r\n            if (searchTerm != nil){\r\n                if (searchTerm!.characters.count > 0){\r\n                    self.newsSourceAndDelegate?.fetchData(searchTerm!)\r\n                }\r\n            }\r\n        }\r\n        dispatch_sync(concurrentNetworkQueue){\r\n            self.tableView.reloadData()\r\n        }`\r\n\r\nHowever, the tableView does not reload automatically with the correct data, and only reloads upon a pull-to-refresh or a successive search. I've been trying various GCD configs for about an hour now and none of them work. Does someone have a fix? I guess I could spinlock it with a While Loop...\r\n\r\nUpdate: Spinlocks did not resolve the issue and dispatching critical sections to a separate concurrent thread does not guarantee sequential completion.\r\n\r\nSee also #131."},"comment":{"url":"https://api.github.com/repos/uchicago-mobi/2016-Winter-Forum/issues/comments/187297299","html_url":"https://github.com/uchicago-mobi/2016-Winter-Forum/issues/176#issuecomment-187297299","issue_url":"https://api.github.com/repos/uchicago-mobi/2016-Winter-Forum/issues/176","id":187297299,"user":{"login":"tabinks","id":93689,"avatar_url":"https://avatars.githubusercontent.com/u/93689?v=3","gravatar_id":"","url":"https://api.github.com/users/tabinks","html_url":"https://github.com/tabinks","followers_url":"https://api.github.com/users/tabinks/followers","following_url":"https://api.github.com/users/tabinks/following{/other_user}","gists_url":"https://api.github.com/users/tabinks/gists{/gist_id}","starred_url":"https://api.github.com/users/tabinks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tabinks/subscriptions","organizations_url":"https://api.github.com/users/tabinks/orgs","repos_url":"https://api.github.com/users/tabinks/repos","events_url":"https://api.github.com/users/tabinks/events{/privacy}","received_events_url":"https://api.github.com/users/tabinks/received_events","type":"User","site_admin":false},"created_at":"2016-02-22T18:04:18Z","updated_at":"2016-02-22T18:04:18Z","body":"This is not a complete implementation, but shows where you should be putting `dispatch_async` call:\r\n\r\n```swift\r\n    // Create a `NSURLSession` object\r\n    let session = NSURLSession.sharedSession()\r\n\r\n    // Create a task for the session object to complete\r\n    let task = session.dataTaskWithURL(url, completionHandler: { (data, response, error) -> Void in\r\n         // Process the `data`\r\n         // Convert `data` to JSON\r\n         // Update the array the table will show\r\n          // Tell the table to reload on the main thread\r\n         dispatch_async(dispatch_get_main_queue()) { [unowned self] in\r\n             self.tableView.reloadData()\r\n         }\r\n    })\r\n    \r\n    // Start the downloading.  NSURLSession objects are created in the paused\r\n    // state, so to start it we need to tell it to *resume*\r\n    task.resume()\r\n\r\n\r\n```"}}