RE: Async. Notifications in a multi-threaded application
RE: Async. Notifications in a multi-threaded application
- Subject: RE: Async. Notifications in a multi-threaded application
- From: "Jake A. Repp" <email@hidden>
- Date: Wed, 1 Jan 2003 02:32:27 -0800
- Thread-topic: Async. Notifications in a multi-threaded application
Maybe I should be asking something else then.. Which is how I can deliver notifications from a background thread to the UI thread with a standard NSNotification. I need a way to wake up the main UI thread to check it's notification queue immediately. Maybe I could use the object provided in an ealier message:
http://cocoa.mamasam.com/MACOSXDEV/2002/12/2/53016.php
To call a thread on the main UI thread that allows it to wake up itself up?
What would that look like?
I have posted a test harness for this that allows you to toggle run modes, watch the notifications in a table log and operate two threads with an HTTP 'execute' button. The button allows you to queue a command to be executed on the background thread. This is the method that I am using.
http://jrepp.com/src/AsyncNotifications.tgz
I have tried modifying the notification helper in this example to create it's own NSNotificationQueue attached to the defaultCenter but this doesn't solve the problem either.
I will have to experiment with your suggestions. Thanks!
More info on this is at:
http://jrepp.com/cocoabb/viewtopic.php?t=58
-jake
-----Original Message-----
From: Chris Kane [
mailto:email@hidden]
Sent: Tue 12/31/2002 8:10 PM
To: Jake A. Repp
Cc: email@hidden
Subject: Re: Async. Notifications in a multi-threaded application
On Thursday, December 19, 2002, at 11:30 AM, Jake Repp wrote:
> 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.
Well, NSNotificationQueues are not necessarily thread-safe, but I can't
conveniently check the documentation now.
The main question I would have is whether the notifications are not
being received about the time when they are being sent, or are not ever
received. The run loop will need to cycle some before ASAP and Idle
notifications will get pushed out of the queue, and if nothing is
happening on the main thread it might be some time before that happens.
Waiting for your updates until "something else happens" may not be the
behavior you want to get, regardless of what the issue here is. (And if
that's true, then notification queue is not the way to go.)
Chris Kane
Cocoa Frameworks, Apple
_______________________________________________
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.