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

  • SEARCH
  • Home
  • 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 141755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:49:39+00:00 2026-05-11T07:49:39+00:00

Was wondering if anyone knows, or has pointers to good documentation that discusses, the

  • 0

Was wondering if anyone knows, or has pointers to good documentation that discusses, the low-level implementation details of Cocoa’s ‘performSelectorOnMainThread:’ method.

My best guess, and one I think is probably pretty close, is that it uses mach ports or an abstraction on top of them to provide intra-thread communication, passing selector information along as part of the mach message.

Right? Wrong?

Update 09:39AMPST

Thank you Evan DiBiase and Mecki for the answers, but to clarify: I understand what happens in the run loop, but what I’m looking for an answer to is; "where is the method getting queued? how is the selector information getting passed into the queue?" Looking for more than Apple’s doc info: I’ve read ’em

Update 14:21PST

Chris Hanson brings up a good point in a comment: my objective here is not to learn the underlying mechanisms in order to take advantage of them in my own code. Rather, I’m just interested in a better conceptual understanding of the process of signaling another thread to execute code. As I said, my own research leads me to believe that it takes advantage of mach messaging for IPC to pass selector information between threads, but I’m specifically looking for concrete information on what is happening, so I can be sure I’m understanding things correctly. Thanks!

Update 03/06/09

I’m look for the lowest-level detail of the mechanism used by performSelectorOnMainThread: and the like, and as I mentioned earlier, I suspect it has something to do with Mach ports but I’d really like to know for sure.

  • 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. 2026-05-11T07:49:40+00:00Added an answer on May 11, 2026 at 7:49 am

    Yes, it does use Mach ports. What happens is this:

    1. A block of data encapsulating the perform info (the target object, the selector, the optional object argument to the selector, etc.) is enqueued in the thread’s run loop info. This is done using @synchronized, which ultimately uses pthread_mutex_lock.
    2. CFRunLoopSourceSignal is called to signal that the source is ready to fire.
    3. CFRunLoopWakeUp is called to let the main thread’s run loop know it’s time to wake up. This is done using mach_msg.

    From the Apple docs:

    Version 1 sources are managed by the run loop and kernel. These sources use Mach ports to signal when the sources are ready to fire. A source is automatically signaled by the kernel when a message arrives on the source’s Mach port. The contents of the message are given to the source to process when the source is fired. The run loop sources for CFMachPort and CFMessagePort are currently implemented as version 1 sources.

    I’m looking at a stack trace right now, and this is what it shows:

    0 mach_msg 1 CFRunLoopWakeUp 2 -[NSThread _nq:] 3 -[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:modes:] 4 -[NSObject(NSThreadPerformAdditions) performSelectorOnMainThread:withObject:waitUntilDone:] 

    Set a breakpoint on mach_msg and you’ll be able to confirm it.

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

Sidebar

Related Questions

I'm wondering if anyone knows of any existing calculator project or library that has
Was wondering if anyone knows a good alternative to tinymce? I find that it
I was wondering if anyone knows if ProgrammableWeb has a service-API, (such as REST),
I was wondering whether anyone knows definitively if LINQ to SQL has the capability
I was wondering whether anyone knows of any tools available that perform the task
I was wondering if anyone knows of any good Open Source distributed computing projects?
I was wondering if anyone knows of any large sites that use progressive enhancement/CSS3?
I was wondering if anyone knows of a class in objective-C that stops/delays the
I am wondering if anyone has or knows a link from where I can
I'm wondering if anyone knows of a tool that will aggressively rewrite CSS to

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.