0

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.

Nishant Tyagi
  • 9,803
  • 3
  • 38
  • 61

4 Answers4

6

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.

Jack
  • 128,551
  • 28
  • 227
  • 331
1

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

Girish
  • 4,692
  • 4
  • 34
  • 54
0

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

Community
  • 1
  • 1
Meet
  • 4,864
  • 3
  • 23
  • 38
0

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.

Jeffery Thomas
  • 41,379
  • 8
  • 92
  • 115