grand-central-dispatch

Firebase freezes UI even when using DispatchQueue

时光毁灭记忆、已成空白 提交于 2020-01-02 18:03:51
问题 From my understanding, Firebase performs operations off the main thread and shouldn't pause the UI while doing so. The code below is a simplified example, but everywhere in my code, where I have a Firebase observer with code that updates the UI, the UI freezes while Firebase downloads data. I've tried writing the same code in a new, clean project, and then the problem no longer exist. Could the problem be the installation of Firebase through pods? I'm also using GeoFire, could that affect in

Waiting for CLGeocoder to finish on concurrent enumeration

左心房为你撑大大i 提交于 2020-01-02 09:55:46
问题 I have the following bit of code in a class method NSDictionary *shopAddresses = [[NSDictionary alloc] initWithContentsOfFile:fileName]; NSMutableArray *shopLocations = [NSMutableArray arrayWithCapacity:shopAddresses.count]; [shopAddresses enumerateKeysAndObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(id key, ShopLocation *shopLocation, BOOL *stop) { CLGeocoder *geocoder = [[CLGeocoder alloc] init]; [geocoder geocodeAddressString:shopLocation.address completionHandler:^(NSArray

IOS thread pool

风流意气都作罢 提交于 2020-01-02 09:19:13
问题 I've got this method -(void)addObjectToProcess(NSObject*)object; and i want this method to add the object to process queue which can process up to 4 objects in parallel. i've created my own dispatch_queue and semhphore _concurrentQueue = dispatch_queue_create([queue_id UTF8String],DISPATCH_QUEUE_CONCURRENT); _processSema = dispatch_semaphore_create(4); and the implementation of the method is: -(void)addObjectToProcess(NSObject*)object { dispatch_semaphore_wait(self.processSema, DISPATCH_TIME

Is this safe to call wait() of DispatchSemaphore several times at one time?

馋奶兔 提交于 2020-01-02 03:52:05
问题 I got three dispatched threads named queueA, queueB, queueC. Now I want the queueA executed after queueB and queueC done. So I tried to implement it by DispatchSemaphore . My Problem is: Is this safe to call wait() two times in a thread at one time to make the semaphore 2? self.semaphore.wait() // +1 self.semaphore.wait() // +1 The following is the entire test code: class GCDLockTest { let semaphore = DispatchSemaphore(value: 0) func test() { let queueA = DispatchQueue(label: "Q1") let queueB

How to achieve concurrent task through NSOperation? [closed]

南楼画角 提交于 2020-01-01 19:35:15
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I am new to NSoperation . NSoperation is a singleshot object. How can we achieve multiple operations concurrently through NSoperation

objc_release EXC_BAD_ACCESS

蹲街弑〆低调 提交于 2020-01-01 19:16:49
问题 Unable to determine what is going on with this error. I am uploading a file in multiple segments. I have threaded my api calls into 7 concurrent threads. Here is the assembly code that it stops at. Here is my printed stack trace Finally the Stack window I do not have any DISPATCH_QUEUE_PRIORITY_LOW except for a #define for dispatch_get_low() and I do not have any calls to dispatch_get_low() as a little background, I am developing my app from xcode 4.4 and recently installed GM Seed 4.5 to

Implementing concurrent read exclusive write model with GCD

拜拜、爱过 提交于 2020-01-01 15:47:08
问题 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

IOS Grand Central Dispatch with callback method

吃可爱长大的小学妹 提交于 2020-01-01 09:14:30
问题 I haven't used GCD or much threading in my apps but I've run into a situation where I need to run a method or two off another thread. Once this method completes I need to call another method using the main thread from a callback. I've been searching around to see how to detect when a thread has finished the operation but still not too clear on the subject. I created a test app and just used the viewDidLoad method for a quick example. - (void)viewDidLoad { [super viewDidLoad]; // Do any

Mutating array while reading, not enumerating

馋奶兔 提交于 2020-01-01 07:29:08
问题 If I have two different threads via GCD accessing an NSMutableArray and one is merely creating a new array based off the mutable array while the other thread is deleting records from the array, should I expect this to be a problem? That is, shouldn't the copy, which I presume is merely "reading" the array, just get whatever happens to be in the array at that moment? I am not enumerating the array in either thread, but it is still crashing. As soon as I remove the read routine, it works fine.

dispatch_sync call into a dispatch_async call

给你一囗甜甜゛ 提交于 2020-01-01 05:19:10
问题 I get some doubts about behavior of this code : dispatch_async(queue, ^{ sleep(2); NSLog(@"step1"); dispatch_sync(queue, ^{ sleep(3); NSLog(@"step 2"); }); NSLog(@"step 3"); }); From these rows i expected to get as output step1 -> step3 -> step2 but i obtain only step1 . If i change dispatch_sync with dispatch_async it works as expected, Does dispatch_sync into a dispatch_async call create this kind of problem ? Edit after answers ---------------- This case create a deadlock: You can check