• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting disk mount notification with Foundation tools
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting disk mount notification with Foundation tools


  • Subject: Re: Getting disk mount notification with Foundation tools
  • From: Bill Bumgarner <email@hidden>
  • Date: Sun, 9 Jun 2002 17:23:56 -0400

That sounds like a potential feature request to be filed to bugreport.apple.com.

Let me clarify something before more confusion is generated: There doesn'
t need to be a running run loop to post or receive notifications [NSNotification]. A notification is delivered immediately.

However, there does need to be a running run loop to handle distributed notifications and to handle messages received via an NSConnection. In effect, a distributed notification is actually just a standard notification that is triggered by an event-- likely an NSConnection message-- that requires a running NSRunLoop to be posted in the first place. That is, the mechanism that receives the workspace event and generates the notification requires a run loop to receive the message from the workspace itself.

So, it sounds like the workspace receives the remote message that a volume was mounted/unmounted in the main runloop / thread and posts the notification there because notifications are not thread specific.

In the context of both command line tools and Cocoa based applications, one needs to allow the main thread's NSRunLoop to run. If you need a main thread that waits on device I/O, does work, or otherwise sleeps [to use Mike's example], then that thread should be separate from the main thread-- it should be a worker thread.

The alternative is to periodically poll the runloop in your main thread. NSRunLoop provides API to process one event at a time -- if you invoke -runMode:beforeDate: with [NSDate date] as the date, it will process exactly one event before returning YES.

In Mike's case, he can likely [maybe not-- I don't pretend to have a clue what his code does outside of this and the previous post :-) ] replace the call to sleep() (or equivalent) to a call to NSRunLoop's runBeforeDate:, then use -runMode:beforeDate: to periodically process pending events in his main thread.

The feature request: Either document explicitly exactly which thread various notifications arrive in or add functionality where the thread within which an observer of-- direct or indirect-- remote notifications is added is the thread within which the notification is received.

b.bum

On Sunday, June 9, 2002, at 04:41 PM, email@hidden wrote:

Date: Sun, 09 Jun 2002 09:31:29 -0600
Subject: Re: Getting disk mount notification with Foundation tools
From: Mike Vannorsdel <email@hidden>
To: Cocoa Dev <email@hidden>

I do have a ready run loop for the notifications, but your answer reminded
me about something. Notifications seem to only arrive in the main run loop,
rather than the run loop where the observer was added. In my daemon, the
main loop is always busy doing work or sleeping while waiting on device I/
O.
I had a different thread that was registered as the observer, which also
runs various timers. The workspace notifications were coming to the main
thread, which never had time to process them. I'll have to do some redesign
to get this working. Thanks.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Where does one add the $CLASSPATH environment variable?
      • From: Conrad Taylor <email@hidden>
    • Re: Getting disk mount notification with Foundation tools
      • From: Mike Vannorsdel <email@hidden>
  • Prev by Date: DoubleClick in a NSTableView
  • Next by Date: Re: Getting disk mount notification with Foundation tools
  • Previous by thread: Re: Getting disk mount notification with Foundation tools
  • Next by thread: Re: Getting disk mount notification with Foundation tools
  • Index(es):
    • Date
    • Thread