Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ equivalent for NSOperation and NSOperationQueue

Please advise me to how to achieve NSOperation and NSOperationQueue functionality in C++.

like image 353
user1908860 Avatar asked Dec 21 '12 01:12

user1908860


People also ask

What is difference between dispatch queue and NSOperationQueue?

NSOperationQueue can be more suitable for long-running operations that may need to be cancelled or have complex dependencies. GCD dispatch queues are better for short tasks that should have minimum performance and memory overhead.

What are the differences and similarities between GCD and NSOperation?

Grand Central Dispatch is a low-level C API that interacts directly with Unix level of the system. NSOperation is an Objective-C API and that brings some overhead with it. Instances of NSOperation need to be allocated before they can be used and deallocated when they are no longer needed.

Which is the best of GCD Nsthread or NSOperationQueue?

NSOperationQueue works best when tasks are discrete, synchronous and live in the same thread (eg they are more or less atomic), the queue can be used as basic thread pool though in almost any situation.

What is NSOperation and NSOperationQueue in iOS?

An operation queue invokes its queued NSOperation objects based on their priority and readiness. After you add an operation to a queue, it remains in the queue until the operation finishes its task. You can't directly remove an operation from a queue after you add it. Note.


2 Answers

NSOperation is a class for managing non-critical tasks. You create Operations, and place them on the NSOperationQueue and each operation is performed as the app executes.

There is no such "equivalent" in C++. C++ is a language, as NSOperationQueue is part of FoundationKit a part of OSX and iOS, a set of Objective-C objects, that aren't part of the objective-c standard.

What you'll need to research is the Android paradigms for doing task concurrency, and use those. Or you can just manually download the assets from the server, in-lieu of any managed task library.

like image 63
Alan Avatar answered Sep 29 '22 09:09

Alan


A rough substitute for NSOperation: std::packaged_task.

like image 31
John K Avatar answered Sep 29 '22 10:09

John K