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 8043675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:58:52+00:00 2026-06-05T04:58:52+00:00

I have a Cocoa app which launches a new NSThread (Thread A) from within

  • 0

I have a Cocoa app which launches a new NSThread (Thread A) from within applicationDidFinishLaunching.

Thread A successfully creates an RFCOMM connection then spawns another NSThread (Thread B), passing the established IOBluetoothRFCOMMChannel to Thread B.
Thread B creates a IOBluetoothRFCOMMChannelDelegate and calls setDelegate on IOBluetoothRFCOMMChannel with it and then runs its current NSRunLoop.
Thread A then waits for Thread B to signal a sync object.

The intent is that, when data arrives, Thread B’s NSRunLoop will execute the delegate which copies the received data and signals Thread A to read it.

However, the delegate never gets called because Thread B’s NSRunLoop has no input sources.
I imagined that setDelegate would create an input source on it.
The only way I can get the delegate called is if I have Thread A wait on its own NSRunLoop instead of wait on the sync object. In that case, the delegate gets executed.

But that arrangement will not work for me. Eventually, my code will just be a library that exposes a C API that is a standard and is only suitable as a procedurally flowing set of functions. Thread A will be someone else’s Thread (maybe main maybe not) and will call into my library in a procedural way.

1) I thought that the thread/runloop which registered for a delegate callback (Thread B) was the one that would get the input source and execute the callback in its runloop. But Thread A’s NSRunLoop gets the input source instead, Why? What’s the expected relationship between these things?

2) How can I get Thread B to get the input source and be the thread that executes the delegates?

Thanks for any and all help.

My Thread B is below:

@implementation CBaiHardwareBluetoothEventThread
- (void) runEventThread: (IOBluetoothObjectID)deviceID
{   
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

    NSRunLoop* myRunLoop = [NSRunLoop currentRunLoop];

    CallbackDelegate* cd = [[CallbackDelegate alloc] init];

    IOBluetoothRFCOMMChannel* myOBJCChannel = [IOBluetoothRFCOMMChannel withObjectID:deviceID];

    [myOBJCChannel setDelegate:cd];

    do{
        [myRunLoop runUntilDate:[NSDate distantFuture]];
        cout << __FUNCTION__ << " this should not be returning but it is ???" << endl;
        usleep(1000000);//avoid the unintentional hard loop that happens
    }while(1); //forever for now

    [pool release];
}
@end
  • 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-05T04:58:54+00:00Added an answer on June 5, 2026 at 4:58 am

    IOBluetooth and threading is messy. You’ll have to work this stuff out by trial and error. If it seems that the callbacks happen on the thread that opened the connection, then you’ll have to open the connection on the thread where you need the callbacks. Also, this behavior often changes between OS releases…

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

Sidebar

Related Questions

I have a Cocoa application (.app) and I would like to launch it from
I have a Cocoa app which interacts with a server and displays a GUI.
I have created Cocoa app which is type of launch agent. To distribute this
I have a Cocoa app with a ManMenu.xib, in which the main menu is
I have an NSMenu instance, through which all communication with the Cocoa app will
Environment: xcode 3.2.1, document-based core-data application. I have a document-based cocoa app which uses
I have a Cocoa Mac image editing app which lets users export JPEG images.
I have a MainViewController in my Cocoa Touch app which shows a status view
I've successfully implemented a NSDocument class in my Cocoa App which is also able
I have two string properties setup in my cocoa application's app delegate which are

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.