Reputation: 2258
If I have a background thread doing some network stuff, and some of the background methods make 'performSelectorOnMainThread' calls, will/can these calls interrupt execution of the current code block (which is being executed on the main thread)?
Upvotes: 0
Views: 647
Reputation: 34912
If waitUntilDone
is set to YES
, then absolutely it will definitely interrupt execution of the code calling performSelectorOnMainThread
. If it's set to NO
then it will queue the selector to be performed on the main thread.
If the caller of performSelectorOnMainThread
is not the main thread, then whether or not the selector gets run before your "current code block" finishes will depend entirely upon the state the CPU is in. There might be more than one CPU so you might have 2 of your threads scheduled at the same time, or just the OS might have decided to schedule the main thread instead of your current thread after some time.
So basically, yes, these calls can interrupt execution of the current code block, just in the same way as you should be familiar with from multi-threaded programming.
[By "current code block" I am assuming you mean the caller of performSelectorOnMainThread
]
Update:
Ah, right, you mean "Can it interrupt the code which is currently being executed on the main thread?". The answer to that, is definitely not. It is scheduled on the main thread's run loop to run next time round the loop.
Upvotes: 1
Reputation: 47094
No, they will and can not. The performSelector
group of methods schedule actions on the run loop. Only after your current code block returns to the run loop, these actions will be performed. (Assuming with "the current code block" you mean your code running on the main thread)
Upvotes: 1