What is the basic difference between NSTimer, NSTask, NSThread and NSRunloop?

前端 未结 3 603
我在风中等你
我在风中等你 2021-01-29 19:26

What is the difference between NSTimer, NSTask, NSThread and NSRunloop and is there a guideline on when to use each of them?<

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-29 19:55

    • NSTimer is a timer object, a way to invoke a selector on an object in the future.
    • NSThread is a thread class. I suppose you know what a thread is.
    • NSTask is a process class, a way to run another program from your program.
    • NSOperation (I'm adding to the question) is a very nice abstraction for a single task. You embed your operation in this class and you can easily execute concurrently by means of an NSOperationQueue class.
    • NSRunLoop is the most difficult to understand. In some way abstracts and adapts the select() unix system call, managing input sources and dispatching events and timers on a thread.

    The guideline is the Apple Threading Programming Guide.

提交回复
热议问题