Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8428589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:05:55+00:00 2026-06-10T05:05:55+00:00

Can anyone explain for what is NSRunLoop ? so as I know NSRunLoop is

  • 0

Can anyone explain for what is NSRunLoop? so as I know NSRunLoop is a something connected with NSThread right? So assume I create a Thread like

NSThread* th=[[NSThread alloc] initWithTarget:self selector:@selector(someMethod) object:nil];
[th start];

-(void) someMethod
{
    NSLog(@"operation");
}

so after this Thread finishes his working right? why use RunLoops or where to use ? from Apple docs I have read something but its not clear for me, so please explain as simple as it possible

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:05:56+00:00Added an answer on June 10, 2026 at 5:05 am

    A run loop is an abstraction that (among other things) provides a mechanism to handle system input sources (sockets, ports, files, keyboard, mouse, timers, etc).

    Each NSThread has its own run loop, which can be accessed via the currentRunLoop method.

    In general, you do not need to access the run loop directly, though there are some (networking) components that may allow you to specify which run loop they will use for I/O processing.

    A run loop for a given thread will wait until one or more of its input sources has some data or event, then fire the appropriate input handler(s) to process each input source that is “ready.”.

    After doing so, it will then return to its loop, processing input from various sources, and “sleeping” if there is no work to do.

    That’s a pretty high level description (trying to avoid too many details).

    EDIT

    An attempt to address the comment. I broke it into pieces.

    • it means that i can only access/run to run loop inside the thread
      right?

    Indeed. NSRunLoop is not thread safe, and should only be accessed from the context of the thread that is running the loop.

    • is there any simple example how to add event to run loop?

    If you want to monitor a port, you would just add that port to the run loop, and then the run loop would watch that port for activity.

    - (void)addPort:(NSPort *)aPort forMode:(NSString *)mode
    

    You can also add a timer explicitly with

    - (void)addTimer:(NSTimer *)aTimer forMode:(NSString *)mode
    
    • what means it will then return to its loop?

    The run loop will process all ready events each iteration (according to its mode). You will need to look at the documentation to discover about run modes, as that’s a bit beyond the scope of a general answer.

    • is run loop inactive when i start the thread?

    In most applications, the main run loop will run automatically. However, you are responsible for starting the run loop and responding to incoming events for threads you spin.

    • is it possible to add some events to Thread run loop outside the thread?

    I am not sure what you mean here. You don’t add events to the run loop. You add input sources and timer sources (from the thread that owns the run loop). The run loop then watches them for activity. You can, of course, provide data input from other threads and processes, but input will be processed by the run loop that is monitoring those sources on the thread that is running the run loop.

    • does it mean that sometimes i can use run loop to block thread for a time

    Indeed. In fact, a run loop will “stay” in an event handler until that event handler has returned. You can see this in any app simply enough. Install a handler for any IO action (e.g., button press) that sleeps. You will block the main run loop (and the whole UI) until that method completes.

    The same applies to any run loop.

    I suggest you read the following documentation on run loops:

    https://developer.apple.com/documentation/foundation/nsrunloop

    and how they are used within threads:

    https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html#//apple_ref/doc/uid/10000057i-CH16-SW1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone explain for me what the purpose when we are doing like this
Can anyone explain a parse error like this one: Method 'get_EnableCdn' in type 'System.Web.UI.ScriptManager'
Can anyone explain what advantages there are to using a tool like MSBuild (or
Can anyone explain why this example is thread safe without volatile? http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html In fact,
Can anyone explain to me why this program: for(float i = -1; i <
Can anyone explain why here a = [] ? 1 : 2 a will
Can anyone explain me how to overpass these problems? Description Resource Path Location Type
Can anyone explain to me why there is a dramatic difference in performance between
Can anyone explain to me why, in VBA code for a button on a
Can anyone explain this code to me? Whats the meaning and how to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.