grand-central-dispatch

correct way to wait for dispatch_semaphore in order to wait for many async tasks to complete

你离开我真会死。 提交于 2019-12-04 17:02:05
I have an asynchronous method longRunningMethodOnObject:completion: this method receives an object of type 'Object' - does work with its data and then calls the completion handler. I need to call many different "longRunningMethods" and wait for all to complete. I would like all of the "longRunningMethodOnObject" to run asynchronously (parallel) to each other in the "for" loop. (I am not certain if the "longRunningMethodOnObject" runs in serial to each other but this is more of a general question) I'm not sure I have created a proper semaphore and would appreciate an explanation on the proper

Clarifications on dispatch_queue, reentrancy and deadlocks

江枫思渺然 提交于 2019-12-04 16:36:08
I need a clarifications on how dispatch_queue s is related to reentrancy and deadlocks. Reading this blog post Thread Safety Basics on iOS/OS X , I encountered this sentence: All dispatch queues are non-reentrant, meaning you will deadlock if you attempt to dispatch_sync on the current queue. So, what is the relationship between reentrancy and deadlock? Why, if a dispatch_queue is non-reentrant, does a deadlock arise when you are using dispatch_sync call? In my understanding, you can have a deadlock using dispatch_sync only if the thread you are running on is the same thread where the block is

What happens to tasks in dispatch queues when an app enters inactive/background/suspended states in iOS?

北战南征 提交于 2019-12-04 15:56:22
问题 I've been scouring Apple's documentation on application states and Grand Central Dispatch, but I haven't found a good answer to this question. According to Apple's documentation, on iOS 4.0: The application is in the background but is not executing code. The system moves an application to this state automatically and at appropriate times. While suspended, an application is essentially freeze-dried in its current state and does not execute any code. During low-memory conditions, the system may

Why does my threading seem to fail after a few threads have started on iOS?

一笑奈何 提交于 2019-12-04 15:43:55
I have this code in the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath delegate call: dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:[webUrls objectAtIndex:indexPath.row]]; CMTime timeduration = playerItem.duration; float seconds = CMTimeGetSeconds(timeduration); NSString *duration = [NSString stringWithFormat:@"%f", seconds]; dispatch_async( dispatch_get_main_queue(), ^{ UITableViewCell *updatecell = [tblView cellForRowAtIndexPath:indexPath];

syscall_thread_switch iOS 8.3 race - CocoaLumberjack bug? how to debug this?

南笙酒味 提交于 2019-12-04 15:13:32
I'm hitting a race-condition in my app, where all or all but 1 threads get stuck on syscall_thread_switch whenever I pause debugging. It reproduces much more often on the simulator, but also on the iPad Air. There is ALWAYS at least 2 threads stuck in CocoaLumberjack's queueLogMessage: -- see screenshots. I've never seen this before on 8.1 and 8.2, but i'm hitting it often on 8.3. I'm not claiming this is an 8.3 bug :) This is a level of complexity i've never had to debug before, so i'm not sure what to do. I hope I'm providing enough information, please let me know if you need more (please be

How can I replace deprecated method dispatch_get_current_queue()? [duplicate]

▼魔方 西西 提交于 2019-12-04 15:02:10
问题 This question already has answers here : Alternatives to dispatch_get_current_queue() for completion blocks in iOS 6? (7 answers) Closed 5 years ago . I am developing a chat application using xmppframework in iOS 5; it works perfectly. But I updated my Xcode to 4.5.1, iOS 5 to iOS 6 and my Mac OS to 10.7.5, and the project did not work due to deprecation issues. I replaced all methods with new methods in iOS 6 except this one: dispatch_get_current_queue() How can I replace this method in iOS

UITableView insertRowsAtIndexPaths:WithRowAnimation without freeze UI

别等时光非礼了梦想. 提交于 2019-12-04 14:42:18
问题 I try to understand what is the best practice to use when I work with UITableView with large number of row to insert when the table is visible. This is my behavior: I have one UITableView and one Thread that try to insert a data into this table. I think that make a [UITableView reloadData] is a poor solution for the performance aspect, and I know that UIKit operation are be carried on main thread, for this reason when the datasource update is completed I tried to send a NSNotification to make

Implementing concurrent read exclusive write model with GCD

这一生的挚爱 提交于 2019-12-04 14:40:55
I am trying to understand the proper way of using Grand Central Dispatch (GCD) to implement concurrent read exclusive write model of controlling access to a resource. Suppose there is a NSMutableDictionary that is read a lot and once in awhile updated. What is the proper way of ensuring that reads always work with consistent state of the dictionary? Sure I can use a queue and serialize all read and write access to the dictionary, but that would unnecessarily serialize reads which should be allowed to access the dictionary concurrently. At first the use of groups here sounds promising. I could

c# dispatch queues like in objective c

江枫思渺然 提交于 2019-12-04 13:23:20
问题 I want to mimic the behavior of objective-c dispatch queues in c#. I see that there is a task parallel library but I really don't understand how to use it and was hoping to get some explanation on how. In objective c i would do something like: -(void)doSomeLongRunningWorkAsync:(a_completion_handler_block)completion_handler { dispatch_async(my_queue, ^{ result *result_from_long_running_work = long_running_work(); completion_handler(result_from long_running_work); }); } -(void)aMethod { [self

dispatch_async has lag somewhere, can't find where. is there an NSLog problem?

我是研究僧i 提交于 2019-12-04 13:09:45
问题 So i have this code: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{ //Bunch of code NSLog(@"Test"); }); which runs and returns nslog immediately. But the results of the code only appear on the screen a few seconds delay. Is there a problem with nslog being used here, which means it's called before it would usually, making it seem speedy when really it isn't. I'm confused as to where this delay is coming from, as the NSLog is right at the end of all the code