• 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
Async. Notifications in a multi-threaded application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Async. Notifications in a multi-threaded application


  • Subject: Async. Notifications in a multi-threaded application
  • From: Jake Repp <email@hidden>
  • Date: Thu, 19 Dec 2002 11:30:03 -0800

I have an application that currently is trying to use two threads to get it's work done. The main thread that launches the application serves the UI and handles dispatching requests to a shared queue of commands. These command objects encapsulate all the necessary work that will be done by a second thread that runs in the background.

The second thread pops threads off of the work queue processes the request, grabs some XML data from an HTTP server, parses the results of the request and then posts a notification with the results of the parsed response.

The method I'm using to post the notification looks like this:

[code]
NSNotification *notification = [NSNotification notificationWithName:inNotificationName object:inObject];

// enqueue the notification for processing at the end of
// the main run loop
[mainQueue
enqueueNotification:notification
postingStyle:NSPostASAP coalesceMask:NSNotificationNoCoalescing
forModes:nil];
[/code]

In the above code the mainQueue is a pointer to the NSNotificationQueue for the main UI thread that is cached when the application starts up.

I have tried every posting style available and none of them will reliably post the notification to the main thread in all conditions. Maybe I am missing something about the NSRunLoop but the documentation says that passing nil for modes will make the the notification post under all run loop modes.

I know that the application is in the default run mode and if I break in the debugger I can examine mainQueue and [NSNotificationQueue defaultQueue] for the main thread, they are the same object and depending on the posting style the internal pointer of the queue will have been set for that style (asap, idle, etc).

This seems to be a bug to me, I have not been able to solve this problem though much hard work and research so maybe someone can offer a suggestion or solution to this problem. Otherwise I'm at the point where I believe this is a bug or a fault in the documentation (which I have read through at least a half-dozen times).

Incidentally I found a post on http://groups.google.com of someone having this same problem when posting with the NSPostWhenIdle style and the notification not being processed. The GNUstep programmer responsible for that code admitted it was a bug and fixed it right away.


-jake
_______________________________________________
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:
    • Re: Async. Notifications in a multi-threaded application
      • From: Chris Kane <email@hidden>
  • Prev by Date: Re: Newbie NSWindow question
  • Next by Date: Re: NSUserDefauts - Am I Missing the Obvious?
  • Previous by thread: Re: Why is this code leaking memory?
  • Next by thread: Re: Async. Notifications in a multi-threaded application
  • Index(es):
    • Date
    • Thread