Câu hỏi phỏng vấn Objective-C
Câu hỏi

What mechanisms does iOS provide to support multi-threading?

Câu trả lời

iOS provides several mechanisms to support multithreading and concurrency in Objective-C applications:

Grand Central Dispatch (GCD)

GCD is a low-level API that simplifies concurrent code execution on multicore hardware. It provides a pool of threads managed by the system and allows you to submit tasks to queues. GCD offers two main types of queues:

  • Serial queues execute tasks in the order they are added, one at a time[4][5]
  • Concurrent queues execute multiple tasks concurrently[4][5]

NSThread

NSThread allows you to create and manage threads directly. You can create a new thread by initializing an NSThread object and specifying the target object and selector to be executed on the new thread[3].

NSOperation and NSOperationQueue

NSOperation provides an object-oriented way to represent tasks. NSOperationQueue manages a collection of NSOperation objects, executing them concurrently or serially. Operations can have dependencies, allowing you to define execution order[4].

Synchronization Mechanisms

To prevent race conditions and ensure thread safety when sharing data across threads, iOS provides several synchronization mechanisms:

  • @synchroni...
middle

middle

Gợi ý câu hỏi phỏng vấn

middle

When would you use Categories over Inheritance and vice versa?

middle

What's the difference between the atomic and nonatomic attributes?

middle

What are some limitations and problems you can face with categories?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào