Is performSelector: onThread: withObject: waitUntilDone: in order?

I have an Objective-C class that spins a background thread and starts NSRunLoop. I would like to deliver messages to the background thread from the main thread (yes, exclusively from the main thread). For this, I plan to use the built-in performSelector:onThread:withObject:waitUntilDone:.

I am wondering if it can be assumed that the order in which I send messages this way will be the order in which they are received in the background thread. Obviously, the question is controversial if several threads are calling performSelector:onThread:withObject:waitUntilDone:at about the same time, but since I will only call it from the main thread, do I guarantee an ordered ordering?

+4
source share
1 answer

According to Apple documentation:

This method queues a message in the execution loop of the target thread using the default startup loop modes, that is, modes associated with the NSRunLoopCommonModes constant. As part of its usual loop cycle processing, the target thread deactivates the message (provided that it is started in one of the default launch cycle modes) and calls the desired method.

A queue is usually an ordered data structure. The fact that he does not state that he can perform in any order means that they will be executed in order.

+2
source

Source: https://habr.com/ru/post/1525865/


All Articles