nsoperationqueue

What's the best way to set up concurrent execution of for loops in Objective C?

☆樱花仙子☆ 提交于 2019-12-08 12:10:23
问题 I have a situation with a time-intensive for loop like this: int sum = 0; for (int i = 0; i < max; ++i) sum += dosomething(i); The do something(i) calls are independent. This cries out for multithreading. Using NSOperationQueue on a two-core machine, I can do this: int __block midpoint; int __block sum1; int __block sum2; midpoint = max/2; sum1 = 0; sum2 = 0; NSOperationQueue *queue = [[NSOperationQueue alloc] init]; NSOperation *operation = [NSBlockOperation blockOperationWithBlock: ^{ for

NSOperationQueue and UITableView release is crashing my app

淺唱寂寞╮ 提交于 2019-12-08 12:02:54
问题 This is by far the weirdest problem I've been stuck with. I have a UIViewController on a UINavigationController and I want to call a method at viewDidAppear using NSInvocationOperation so it can run on a back thread when the view becomes visible. The problem is that if I pop the view controller BEFORE the operation (in this case the testMethod method) completes running, the app crashes. Everything works fine if I pop the view controller AFTER the operation runs it's course. When the app

Queue of AFHTTPRequestOperations creating Memory Buildup

别等时光非礼了梦想. 提交于 2019-12-08 02:44:24
问题 I just updated to AFNetworking 2.0 and I am re-writing my code to download data & insert it into Core Data. I download JSON data files (anywhere from 10-200mb files), write them to disk, then pass them off to background threads to process the data. Below is the code that downloads the JSON & write it to disk. If I just let this run (without even processing the data), the app uses up memory until it is killed. I assume as the data is coming in, it is being stored in memory, but once I save to

Cancelling NSOperation from NSOperationQueue cause crash

倖福魔咒の 提交于 2019-12-07 22:55:22
问题 I'm trying to build a download manager class that packets all the async download (every op has its own thread) operation in an NSOperation subclass to add them later in an NSOperationQueue. The download manager class (a singleton) also exposes few methods to work on the queue and cancel operations that matches some requirements. Those are steps to start creating kind of a Class Cluster(Abstract Factory) that returns different kinds of NSOperation for different types of common operation

[NSBlockOperation addExecutionBlock:]: blocks cannot be added after the operation has started executing or finished

邮差的信 提交于 2019-12-07 18:14:33
问题 I am trying to start again NSBlockOperation after completing or canceling it, but getting an error? Any one have any idea where is mistake? Thanks let imageURLs = ["http://www.planetware.com/photos-large/F/france-paris-eiffel-tower.jpg", "http://adriatic-lines.com/wp-content/uploads/2015/04/canal-of-Venice.jpg", "http://algoos.com/wp-content/uploads/2015/08/ireland-02.jpg", "http://bdo.se/wp-content/uploads/2014/01/Stockholm1.jpg"] class Downloader { class func downloadImageWithURL(url:String

Barrier operations in NSOperationQueue

筅森魡賤 提交于 2019-12-07 02:03:58
问题 How can we implement dispatch_barrier_async 's equivalent behavior using NSOperationQueue or any user-defined data-structure based on NSOperationQueue ? The requirement is, whenever a barrier operation is submitted it should wait until all non-barrier operations submitted earlier finish their execution and blocks other operations submitted after that. Non-barrier operations should be able to perform concurrently. Barrier operations should execute serially. NB: Not using GCD ,as it doesn't

iOS multiple threads(2)------NSOperation NSOper...

荒凉一梦 提交于 2019-12-06 23:47:13
首先,简单区分这几个类关键词: NSOperation :可以理解程一个“操作”,一个要做的事件,感觉类似如java中的runnable,NSOperation只有添加到线程队列中才能被执行。 NSOperationQueue :可以勉强的叫做线程队列吧,他是专门管理添加到他里面NSOperation,然后根据情况,开启线程执行对应的“操作”,java作用,也有对应的类,或者我们自己写一个队列。 NSOperationQueue的目的就是多线程管理,一个NSOperationQueue 操作队列,就相当于一个线程管理器,而非一个线程。因为你可以设置这个线程管理器内可以并行运行的的线程数量等等。 下面是建立并初始化一个操作队列,而且我们可以设置这个队列每次被处理的“操作(NSOperation)”数量: NSOperationQueue *aQ = [[NSOperationQueue alloc] init]; [aQ setMaxConcurrentOperationCount:10]; 然后,我们后面就可以建立需要操作的任务啦,然后加到操作队列中,就可以实现队多线程啦,ios中,使用NSInvocationOperation(NSOperation的子类)是最简单的多线程编程方式,在iPhone编程中是经常被用到的 /创建一个NSInvocationOperation对象

ios NSOperationQueue, operations all run when added and don't queue

守給你的承諾、 提交于 2019-12-06 15:13:31
问题 So, I have a group of ASINetworkQueues that currently run together resulting in a race condition when it comes to DB saves. I am trying to create an NSOperationQueue that will will queue each of these "sub queues". I currently have created an NSOperation with a main method that kicks off the "sub queue" to start it's download. My problem is that each time I add a sub queue to the main queue using "addOperation" it fires that "main" method straight away so my sub queues run concurrently. I was

How do I repeat an ASIHTTPRequest?

眉间皱痕 提交于 2019-12-06 11:18:36
问题 Given the example code below: // ExampleModel.h @interface ExampleModel : NSObject <ASIHTTPRequestDelegate> { } @property (nonatomic, retain) ASIFormDataRequest *request; @property (nonatomic, copy) NSString *iVar; - (void)sendRequest; // ExampleModel.m @implementation ExampleModel @synthesize request; @synthesize iVar; # pragma mark NSObject - (void)dealloc { [request clearDelegatesAndCancel]; [request release]; [iVar release]; [super dealloc]; } - (id)init { if ((self = [super init])) { //

Queue of AFHTTPRequestOperations creating Memory Buildup

[亡魂溺海] 提交于 2019-12-06 10:56:42
I just updated to AFNetworking 2.0 and I am re-writing my code to download data & insert it into Core Data. I download JSON data files (anywhere from 10-200mb files), write them to disk, then pass them off to background threads to process the data. Below is the code that downloads the JSON & write it to disk. If I just let this run (without even processing the data), the app uses up memory until it is killed. I assume as the data is coming in, it is being stored in memory, but once I save to disk why would it stay in memory? Shouldn't the autorelease pool take care of this? I also set the