Re: Bluetooth and runloops in a dedicated thread.
Re: Bluetooth and runloops in a dedicated thread.
- Subject: Re: Bluetooth and runloops in a dedicated thread.
- From: Dave Keck <email@hidden>
- Date: Tue, 27 Apr 2010 18:53:08 -1000
> I knocked all the code down to the single UI thread and I rediscovered why I need multiple threads. My Obj-C objects give KVC semantics to the bluetooth device. A getter is waiting on a thread signal for the arrival of requested data. The requested data will never arrive since the single thread is in a blocked state. I also now have to turn the bluetooth scanner off to open a connection to a discovered device!
I see. Note that if your getter method blocks until the Bluetooth
operation is complete, your UI will also be blocked. So if the
Bluetooth operation takes too long, you'll get the beachball.
Perhaps your getter could initiate the Bluetooth operation, and in the
meantime return a cached object? If a cached object isn't available or
you want to update the property's value, return a default value for
the property, and initiate a "Loading..." spinner in the UI. Once the
current state of the property is available, it updates the property
which in turn updates the UI, and hides the loading spinner. For a
snappy user experience, I'd try to avoid blocking in a getter method.
> I don't see how to do the bluetooth communications in another process be non-trivial. Is there a simple approach to that?
I implemented a simple custom protocol over Unix pipes, allowing the
parent to direct the child in performing some simple Bluetooth
operations. It certainly wasn't fun to implement, but from what you've
said so far, I think handling the Bluetooth operations in the same
process will work fine in your case if you structure it right.
> My next factoring will be to but the UI thread into a secondary thread, and let bluetooth own the main. Hopefully that will work.
I hate the be the bearer of bad news, but UI code generally needs to
remain on the main thread, too. See:
http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Bluetooth-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden