Note that there are some explanatory texts on larger screens.

plurals
  1. POTwo simultaneous background tasks using NSOperationQueue
    primarykey
    data
    text
    <p>I have two tasks that i need to perform in background simultaneously with different thread priorities:</p> <ol> <li><p>continuously gather and process gyro motion data (high priority)</p> <pre><code>gyroQueue = [[NSOperationQueue alloc] init]; [self.motionManager startDeviceMotionUpdatesToQueue:gyroQueue withHandler:^(CMDeviceMotion *motion, NSError *error){ [self processMotion:motion withError:error]; }]; </code></pre></li> <li><p>Sometimes process images without interfering with motion updates (convert, crop, sesize, etc = 1-2sec) (very low priority)</p> <pre><code>imageProcessingQueue = [[NSOperationQueue alloc] init]; [imageProcessingQueue addOperationWithBlock:^{ [self processImage:[UIImage imageWithData:imageData]]; }]; </code></pre></li> </ol> <p>EDIT: this is what I had in place originally (instead of block operation), and it is still blocking the motion updates:</p> <pre><code>NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(processImage:) object:[UIImage imageWithData:imageData]]; [operation setThreadPriority:0.0]; [operation setQueuePriority:0.0]; [imageProcessingQueue addOperation:operation]; </code></pre> <p>It seems as both of these tasks are being executed on the same background thread (due to NSOperationQueue nature?), and processing of an image blocks the gyroQueue updates until it's done, which is what i am trying to avoid.</p> <p>How can I spawn two separate threads using NSOperationQueue, and assign veryHigh &amp; veryLow priorities accordingly?</p> <p>EDIT: this question is still open, i am using Travor Harmon's image resize functions for image resize. Can someone confirm if it's thread safe?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload