views:

149

answers:

1

Hello everybody,

I am learning Objective-C, I will be developing a video processing application.

I am reading the developer's guide on apple and I ran into Operation objects. I just need some clarifications what the difference between operations & threads, disadvantages, advantages, use cases.

From what I read, operation is higher level of application process/task management. The NSOperationQueue can handle operation resources and concurrency.

What I don't understand is that Operation can be directly run in a thread, I am not too clear on this concept. I am not to clear on the difference between operations & threads.

Please provide me with as much information/background on the two as possible.

Thanks a lot everyone.

+1  A: 

The difference between NSOperation and threads is one of abstraction. A thread is a low-level (operating system-level) construct with which to execute multiple "threads" of code concurrently. Although Cocoa provides the NSThread API, it is essentially a wrapper on the pthreads API. NSOperation is a higher-level abstraction of a task that you wish to execute. NSOperationQueue will schedule execution of a queue of NSOperations so as to maximally utilize the available CPU(s). On a multi-core system, multiple NSOperations will be executed simultaneously using a pool of threads that NSOperationQueue maintains. The advantage of using this higher-level API is that it lets you think about the "operations" you wish to perform rather than how to schedule them. The disadvantage (and hence the advantage of using NSThread directly) is that you have more control over the scheduling of the thread and communication between the thread and other threads (see -[NSObject performSelector:withObject:onThread:]). For atomic tasks, such as video processing, NSOperation is likely the best fit.

Barry Wark
Thanks BarryMy program is a test app for a video diver. So it needs to decode a video file's codec, pass it to the application, and display it in the application window. In my app, multiple frames of the video file are simultaneously being decoded, and there are no guarantee that the decoding frames will be displayed in the file frame orders. As will the decoded frame is displayed on the screen in what I assume is another thread.In your opinion, should I use callback functions, Threads, or Operations. Because the application has specific tasks, I just need work out the operation.
ReachConnection