RE: Diskarbitration callback
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Thread-index: AcixMydKzhdkPHeFTb6rJM4fC5RnfgAjVhkg Thread-topic: Diskarbitration callback Hi Kevin, Thanks for your comments; a couple of responses inline below
And an awkward question: my 'real' code will be in a library, called from both command line tools, and from a cocoa app. Is this run-loop hocus pocus safe in both environments?
Basically it depends on how you expect your code to be used.
A RunLoop is basically a generic construct for waiting on callbacks. They're created on demand (whenever you call and RunLoop function), and map to threads so each thread has one runloop, unless the thread doesn't make any runloop related calls.
[...]
Now, to using it in a library, it depends on what your trying to to. If your trying to create a disk arb wrapper, my suggestion would be to create your own thread, file your callbacks against that threads runloop, and then have your API provide hooks to modify what ever behavior you need to modify (with appropriate locks, etc.). If your trying to do something else, well, I'd need to know more about what your trying to do.
I will say that calling CFRunLoopRun or any of it's similar ilk is almost certainly a bad idea unless your in your own thread. Certainly for GUI apps it's VERY unusual for a run loop to be run directly and will probably result in all sorts of oddities. It's not against the "rules", but it's something you'd need to be very careful about doing- GUI apps generally have lots of things hooked up to the run loop and your running it directly is either going to cause unexpected pauses as other events are delayed, or possibly reentry problems depending on what exactly you do.
That was exactly my concern: I don't mind pauses in a console app, but I didn't want to tie up the gui. My library does 'things' with disks, I need to perform the DAUnmount/eject right in the middle, and I just wanted the same library call to work whether called from console or GUI. However all my 'real' work in the cocoa app, including the call in question, is already done in a background thread, so I get the impression I'm safe to use the same runloop construct within the library. I'm about to try it anyway... Cheers, Andy _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com
participants (1)
-
Andy Green