grand-central-dispatch

kill items in a dispatch_async queue in iOS

自作多情 提交于 2020-01-09 05:06:26
问题 I am running a bunch of items in the background using dispatch_async and sometimes I want to kill what I have in the queue - is this possible? For instance this code is run on a view, and then the user goes back a screen. All of these fired actions keep running regardless of the back navigation. Ideally I would like to kill these items from running: dispatch_async(dispatch_get_global_queue(2, 0), ^{ for (int i=0; i<[self.manufacturers count]; i++) { NSString *manufacturerID = [[[self

Cancel GCD block working in thread

旧街凉风 提交于 2020-01-06 04:51:10
问题 I have the following block which performs a request in the background. How may I cancel this request before it has completed? dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(queue, ^{ NSData *thumbnailData = [NSURLConnection sendSynchronousRequest:request]; ... }); 回答1: You can't. You have to use the asynchronous interface of NSURLConnection to be able to cancel requests. 回答2: You can't cancel once you've dispatched... You can use a

App hangs deleting iCloud Document when following  guideline using NSFileCoordinator and DispatchQueue

♀尐吖头ヾ 提交于 2020-01-05 08:52:46
问题 I have a todo list app that stores document in iCloud as UIDocument object. The following function in the table view controller is created to delete a todo list item both locally and remotely in iCloud but hang the app when executed it via swipe to delete gesture on the table view cell: fileprivate func deleteNote(at indexPath: IndexPath) { let noteDocument = self.noteDocuments[indexPath.row] let fileCoordinator = NSFileCoordinator(filePresenter: nil) fileCoordinator.coordinate(writingItemAt:

App hangs deleting iCloud Document when following  guideline using NSFileCoordinator and DispatchQueue

谁都会走 提交于 2020-01-05 08:51:41
问题 I have a todo list app that stores document in iCloud as UIDocument object. The following function in the table view controller is created to delete a todo list item both locally and remotely in iCloud but hang the app when executed it via swipe to delete gesture on the table view cell: fileprivate func deleteNote(at indexPath: IndexPath) { let noteDocument = self.noteDocuments[indexPath.row] let fileCoordinator = NSFileCoordinator(filePresenter: nil) fileCoordinator.coordinate(writingItemAt:

Synchronizing UI, MKMapView and CLLocationManager delegates

故事扮演 提交于 2020-01-05 08:42:39
问题 I have a ViewController that is set as delegate of MKMapView and CLLocationManager . This ViewController also receives actions from UI buttons. I have a state machine that needs to be updated whenever some UI action happens or when a new location is available (whether it comes from MKMapView or CLLocationManager ) Obviously, the state machine update must be atomic, but I can't seem to find a good mechanism to do so. Here's a snippet of the code: m_locationSerialQueue = dispatch_queue_create(

Memory usage for global GCD queue

大憨熊 提交于 2020-01-05 07:46:50
问题 I have a number of images I am filtering and when I do this in a serial queue that I create ,the memory is released after each block is complete. When I dispatch this work to the global GCD queue the memory doesnt release and gets out of control. I wrapped the statements in an autorelease block but that doesnt seem to make a difference. Is it due to the fact that the thread pool keeps references to the blocks somehow? After a while the memory gets released, but the app will crash before this

Protecting critical code from being called again

我怕爱的太早我们不能终老 提交于 2020-01-04 23:02:01
问题 I need to protect a critical area of my code, which is multi-threaded. I want to prevent it from being called multiple times before the other thread is finished. This is what I am working with: - (void) filterAllEventsIntoDictionary{ // start critical area if (self.sortedKeys.count != 0) { [self.sortedKeys removeAllObjects]; } dispatch_async(self.filterMainQueue, ^{ [self internal_filterAllEventsIntoDictionary]; dispatch_sync(dispatch_get_main_queue(), ^{ [self.tableView reloadData]; }); });

Protecting critical code from being called again

丶灬走出姿态 提交于 2020-01-04 23:01:08
问题 I need to protect a critical area of my code, which is multi-threaded. I want to prevent it from being called multiple times before the other thread is finished. This is what I am working with: - (void) filterAllEventsIntoDictionary{ // start critical area if (self.sortedKeys.count != 0) { [self.sortedKeys removeAllObjects]; } dispatch_async(self.filterMainQueue, ^{ [self internal_filterAllEventsIntoDictionary]; dispatch_sync(dispatch_get_main_queue(), ^{ [self.tableView reloadData]; }); });

Rapid Heap growth with Grand Central Dispatch

懵懂的女人 提交于 2020-01-04 09:36:07
问题 Context: I have an iOS game application which uses GCD. For the application, I have three queues : Main Queue, Game Logic Queue (Custom serial), Physics Queue (Custom serial). Physics Queue is used to do the physics simulation and Game Queue is used to do the game logic. So for every update (every 1/60 seconds), each queue does its respective work and then shares it with other queues by scheduling blocks on the other queues. Problem: With GCD: When I play a game level i.e. the queue are doing

On iOS, can you make a synchronous network request (but not on the main thread) and still get progress callbacks (on a separate, non-main thread)?

こ雲淡風輕ζ 提交于 2020-01-03 05:44:27
问题 On iOS, can you make a synchronous network request (off the main thread) and get progress callbacks (on a separate, non-main thread)? I have have a serial (one-operation-at-a-time) background queue that runs all of time-consuming jobs that don't need to finish right now. I do want to show progress for the download jobs though. It doesn't look like you can instantiate an NSURLConnection and configure a delegate, start synchronous connection, and then get progress callbacks. Is there a way to