grand-central-dispatch

iOS Concurrency - Not reaching anywhere's near theoretical maximum

时光怂恿深爱的人放手 提交于 2019-11-29 17:17:10
I'm new to Grand Central Dispatch and have been running some tests with it doing some processing on an image. Basically I'm running a grayscale algorithm both sequentially and using GCD and comparing the results. here is the basic loop: UInt8 r,g,b; uint pixelIndex; for (uint y = 0; y < height; y++) { for (uint x = 0; x < width; x++) { pixelIndex = (uint)(y * width + x); if (pixelIndex+2 < width * height) { sourceDataPtr = &sourceData[pixelIndex]; r = sourceDataPtr[0+0]; g = sourceDataPtr[0+1]; b = sourceDataPtr[0+2]; int value = (r+g+b) / 3; if (value > MAX_COLOR_VALUE) { value = MAX_COLOR

How can I create a reference cycle using dispatchQueues?

谁都会走 提交于 2019-11-29 17:14:59
I feel that I've always misunderstood that when reference cycles are created. Before I use to think that almost any where that you have a block and the compiler is forcing you to write .self then it's a sign that I'm creating a reference cycle and I need to use [weak self] in . But the following setup doesn't create a reference cycle. import Foundation import PlaygroundSupport PlaygroundPage.current.needsIndefiniteExecution class UsingQueue { var property : Int = 5 var queue : DispatchQueue? = DispatchQueue(label: "myQueue") func enqueue3() { print("enqueued") queue?.asyncAfter(deadline: .now(

dispatch_source_cancel on a suspended timer causes EXC_BAD_INSTRUCTION

最后都变了- 提交于 2019-11-29 16:46:30
问题 I'm trying to cancel and then release a suspended timer but when I invoke 'dispatch_release' on it, I immediately get EXC_BAD_INSTRUCTION. Is this not a valid set of actions to take on a timer? Timer creation & suspension: @interface SomeClass: NSObject { } @property (nonatomic, assign) dispatch_source_t timer; @end // Class implementation @implementation SomeClass @synthesize timer = _timer; - (void)startTimer { dispatch_queue_t globalQ = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY

iOS - how to be notified when a thread (using GCD) ends it's job

青春壹個敷衍的年華 提交于 2019-11-29 15:48:44
问题 I'm start to use GCD, and I need to know when a certain thread has ended it's job. My code: dispatch_queue_t registerDeviceQueue = dispatch_queue_create("RegisterDevice", NULL); dispatch_async(registerDeviceQueue, ^{ [self registerDevice]; dispatch_async(dispatch_get_main_queue(), ^{ [aiRegisterDevice stopAnimating]; }); }); dispatch_release(registerDeviceQueue); I need to know when this tread has ended, so that the UIActivityView can stop. The way it is now, it's stops before the thread ends

iOS: Core image and multi threaded apps

◇◆丶佛笑我妖孽 提交于 2019-11-29 14:57:05
问题 I am trying to run some core image filters in the most efficient way possible. Trying to avoid memory warnings and crashes, which I am getting when rendering large images. I am looking at Apple's Core Image Programming Guide. Regarding multi-threading it says: "each thread must create its own CIFilter objects. Otherwise, your app could behave unexpectedly." What does this mean? I am in fact attempting to run my filters on a background thread, so I can run an HUD on the main thread (see below)

Dispatch queues and asynchronous RNCryptor

泄露秘密 提交于 2019-11-29 14:29:47
问题 This is a follow-up to Asynchronously decrypt a large file with RNCryptor on iOS I've managed to asynchronously decrypt a large, downloaded file (60Mb) with the method described in this post, corrected by Calman in his answer. It basically goes like this: int blockSize = 32 * 1024; NSInputStream *cryptedStream = [NSInputStream inputStreamWithFileAtPath:...]; NSOutputStream *decryptedStream = [NSOutputStream output...]; [cryptedStream open]; [decryptedStream open]; RNDecryptor *decryptor = [

Read-Write lock with GCD

我只是一个虾纸丫 提交于 2019-11-29 14:00:04
问题 My application makes heavy use of GCD, and almost everything is split up in small tasks handled by dispatches. However, the underlying data model is mostly read and only occasionally written. I currently use locks to prevent changes to the critical data structures while reading. But after looking into locks some more today, I found NSConditionLock and some page about read-write locks. The latter is exactly what I need. I found this implementation: http://cocoaheads.byu.edu/wiki/locks . My

Very slow HTML rendering in NSAttributedString

别说谁变了你拦得住时间么 提交于 2019-11-29 13:58:29
问题 I have UITableView with dynamic sizing cells that displays list of comments in HTML format and I faced with the problem that NSAttributedString renders HTML content extremely slow! Here is snapshot from profiler. I tried to put the NSAttributedString initialization to separate thread, but still slow and user sees empty cells while HTML is being rendered and finally when it finished rendering cell is not layout properly. dispatch_async(GlobalQueue, { let html = NSAttributedString( data: self

iOS MKMapShapshotter completion block is not always being called

纵饮孤独 提交于 2019-11-29 13:43:42
I am trying to use the new iOS7 MKMapSnapshotter to generate a static map image. Whenever my app needs a map, I call the following: MKMapSnapshotter *snapshotter = [[[MKMapSnapshotter alloc] initWithOptions:theOptions] autorelease]; dispatch_queue_t aQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0); DebugLog(@"Snapshotter allocated %@ and run on queue %@", snapshotter, aQueue); [snapshotter startWithQueue:aQueue completionHandler:^(MKMapSnapshot *snapshot, NSError *error) { DebugLog(@"Snapshotter completion block %@", snapshotter); // perform selector on main thread to

How to write into an array from a dispatch_apply (GCD) loop?

天涯浪子 提交于 2019-11-29 10:45:18
I have written code to calculate the dynamics of a large set of coupled master equation using the Runge-Kutta-method. The code contains a lot of for-loops, where each step is independent. I intend to use Grand Central Dispatch to speed up the program. I based my attempt on an example I found at http://www.macresearch.org/cocoa-scientists-xxxi-all-aboard-grand-central . Neither my code nor the example on macresearch compile on my machine (MacOSX 10.6.8 Xcode 4.0.2). So here is my code: ... double values[SpaceSize], k1[SpaceSize]; for ( int t=1 ; t<Time ; t++ ) { dispatch_queue_t queue =