Async. Notifications stalling on the notification queue
Async. Notifications stalling on the notification queue
- Subject: Async. Notifications stalling on the notification queue
- From: Jake Repp <email@hidden>
- Date: Wed, 4 Dec 2002 17:26:05 -0800
I have a problem with notifications being delivered to thread using the
NSPostASAP posting style. I have registered to recieve the
notifications in other objects but do not receieve them in all cases
when using the NSPostASAP or NSPostWhenIdle style. If I use the
NSPostNow style, the notification is posted but breaks other areas
because I can't have UI updates happening in the worker thread. The
strange thing is that NSPostASAP does occasionally work if the
application is doing other things. I have tried to force this behaviour
by calling run on the UI's main run loop but that has other problems
and doesn't allow the notifications to be processed either.
I can break in a debugger and examine the notification queue for the UI
thread and I see that the notifications that were enque'd are sitting
there waiting to be processed but nothing ever happens with them.
In a worker thread I'm using the following code to post the
notification:
static NSNotificationQueue *mainQueue;
static NSRunLoop *mainLoop;
+ (void) postNotificationName: (NSString*) inNotificationName
object:(id) inObject;
{
NSNotification *notification;
assert(mainQueue && mainLoop);
notification = [NSNotification notificationWithName:inNotificationName
object:inObject];
DBG2("Posting notification:%s, mainLoop: %s",
[[notification name] cString],
[[mainLoop currentMode] cString]);
// enqueue the notification for processing at the end of
// the main run loop
// TODO: figure out correct mode: NSPostWhenIdle, NSPostASAP, NSPostNow
[mainQueue enqueueNotification:notification
postingStyle:NSPostASAP
coalesceMask:NSNotificationNoCoalescing forModes:nil];
// FIXME: this doesn't help at all either:
// [mainLoop run];
}
+ (void) setNotificationDestination: (NSRunLoop*) inMainLoop
queue:(NSNotificationQueue*) inMainQueue
{
mainLoop = inMainLoop;
mainQueue = inMainQueue;
}
I have a notification sink to listen setup so:
- (void) debugNotificationSink: (NSNotification*)inNotification
{
id object = [inNotification object];
NSString *name = [inNotification name];
if([name hasPrefix:@"ICMS_"])
{
DBG4("--- Notification: %s, Object: 0xx, In Thread: 0xx
RunMode: %s",
[name cString],
(uint)object,
(uint)[NSThread currentThread],
[[[NSRunLoop currentRunLoop] currentMode] cString]
);
}
}
- (IBAction) switchDebugNotification: (id) sender
{
debugNotify = !debugNotify;
if(debugNotify) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(debugNotificationSink:)
name:nil
object:nil];
} else {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
[self updateDebugNotifyMenuItem:sender];
}
Thanks,
-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.