grand-central-dispatch

EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) on dispatch_semaphore_dispose

∥☆過路亽.° 提交于 2019-12-28 04:49:10
问题 I am getting EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) on dispatch_semaphore_dispose but don't really know how to track down the root cause of this. My code makes use of dispatch_async, dispatch_group_enter and so on. UPDATE: The cause of the crash is due to the fact that the webserviceCall (see code below) never calls onCompletion and when the code is run again, I got the error EXC_BAD_INSTRUCTION. I verified this is indeed the case, but not sure why or how to prevent this. Code

Process Array in parallel using GCD

自古美人都是妖i 提交于 2019-12-28 04:08:09
问题 I have a large array that I would like to process by handing slices of it to a few asynchronous tasks. As a proof of concept, I have the written the following code: class TestParallelArrayProcessing { let array: [Int] var summary: [Int] init() { array = Array<Int>(count: 500000, repeatedValue: 0) for i in 0 ..< 500000 { array[i] = Int(arc4random_uniform(10)) } summary = Array<Int>(count: 10, repeatedValue: 0) } func calcSummary() { let group = dispatch_group_create() let queue = dispatch_get

Handle writeData method on NSFileHandle on main thread

杀马特。学长 韩版系。学妹 提交于 2019-12-25 18:27:55
问题 Since writeData call is synchronous, what is the best way to use it when we call writeData from a different thread other than main queue? For instance, a web service is called to fetch some data and the completionHandler is assigned to the web service call. Now this completion handler will be executed on a different thread (not on main queue). I have seen my app getting stuck, on writeData method for 5 to 6 mins. This is the only thing I can suspect right now. I tried wrapping around my

How do I return a value from a Helper Class to a view controller?

江枫思渺然 提交于 2019-12-25 16:47:04
问题 I have a viewcontroller that calls a HelperClass class method in its viewDidLoad like so: - (void)viewDidLoad{ [super viewDidLoad]; self.usersArray = [SantiappsHelper fetchUsers]; } That class method looks like this: +(NSArray *)fetchUsers{ NSString *urlString = [NSString stringWithFormat:@"http://www.myserver.com/myApp/getusers.php"]; NSURL *url = [NSURL URLWithString:urlString]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy

dispatch_queue and return data

跟風遠走 提交于 2019-12-25 16:42:57
问题 I'm trying to write this method that returns an NSArray . My NSMutableArray (friendUsers) adds the objects right, but outside the dispatch_async the array is empty. I try to add the users in the main queue ( as ashowed) but the array is empty to. Any ideas ? Thanks for all your help. - (NSArray *)checkUsersInGroup { NSMutableArray *friendUsers = [[NSMutableArray alloc] init]; dispatch_queue_t checkUSers = dispatch_queue_create("CheckUsers", NULL); dispatch_async(checkUSers, ^{ NSArray

dispatch_semaphore_signal never being executed because of the wait

徘徊边缘 提交于 2019-12-25 15:16:29
问题 I am trying to take two pictures and want them to run in order. The method for capturing pictures is done using a method that runs asynchronously. I currently use semaphores to try to synchronize this, but it stops the program from running. I believe this is because the completionHandler is run on the same thread, and since the thread is locked, it can't execute to free the semaphore. Here is my current code: camera_sema = dispatch_semaphore_create(0); [photoOutput

Can __weak self turn nil in the middle of the block?

情到浓时终转凉″ 提交于 2019-12-25 08:58:20
问题 When using a __weak self reference in my block that runs on a background thread, do I only need to check for nil in the beginning, or can the __weak self become nil even during execution after the first nil test has passed? I want to access some ivars from self in the block and I need the latest values at the time the block is executing. 回答1: If no one is holding a reference to self then yes. You can mitigate this by taking a strong reference in the block __weak __typeof(self) weakSelf = self

filtering NSFetchedResultController via searchBar without loading base pauses?

泪湿孤枕 提交于 2019-12-25 08:18:39
问题 i try to create search in big Core Data base (32 thousand objects) but when i added some text to the UISearchBar i have some lags (because my base is updating with new search Predicate) how to fix this? how can i update my base in background thread? fetchedResultController code lazy var context: NSManagedObjectContext = { let appDelegate = (UIApplication.shared.delegate as? AppDelegate) let context = appDelegate!.managedObjectContext return context//appDelegate!.managedObjectContext }() lazy

Objective C how to stop infinte loop while moving from first VC to 2nd

本小妞迷上赌 提交于 2019-12-25 07:49:18
问题 I am trying to build a splash screen so I want the 1st View Controller to move to 2nd ViwController automatically after 3.0 sec I have tried the below method but an infinite loop has started what should i do ,how should I stop on second view controller. - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSLog(@"%p", self); NSLog(@"1st Controller"); [self.navigationController setNavigationBarHidden:YES animated:YES]; dispatch

Grand Central Dispatch Multiple DispatchGroups

自闭症网瘾萝莉.ら 提交于 2019-12-25 07:40:00
问题 I have three async calls. One returns data, and two return images from S3 using firebase. I have one background DispatchQueue, and three dispatch groups. I need a way for them to execute synchronously, but they don't! I have tried everything, and .notify executes immediately, which is wrong. The output of this is : images done all is done group.notify is done getImages() is done What I want to understand is why is imagesdone executed before group.notify is done? I need to execute the first