I am little confused whether NSRunLoop is thread safe or not. So I need some clarification is it thread safe or not and why?
Any help is appreciable.
I am little confused whether NSRunLoop is thread safe or not. So I need some clarification is it thread safe or not and why?
Any help is appreciable.
There a warning right in the beginning of the NSRunLoop official reference documentation:
Warning: The NSRunLoop class is generally not considered to be thread-safe and its methods should only be called within the context of the current thread. You should never try to call the methods of an NSRunLoop object running in a different thread, as doing so might cause unexpected results.
No it is not.
Read the documentation from NSRunLoop Reference
Warning: The NSRunLoop class is generally not considered to be thread-safe and its methods should only be called within the context of the current thread. You should never try to call the methods of an NSRunLoop object running in a different thread, as doing so might cause unexpected results.
Also check the NSRunLoop answer on SOF
Not only is it not thread-safe, it is expressly thread-specific. Each thread that passes messages between NSObjects must contain its own NSRunLoop. Accessing another thread's runloop can mess up tracked cycles like -autoreleased objects, timed events like NSTimers, and sub-runloops setup by things like -runUntilDate:. In addition, I'm assuming that NSRunLoop will use thread-specific data to store some information. That means you could cause data mismatch between thread-specific data and object stored data.