문제

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.

다른 팁

NSRunLoop is not thread safe. See Apple's Guidelines for more reference.

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top