RE: Threads and messages
RE: Threads and messages
- Subject: RE: Threads and messages
- From: "Jake A. Repp" <email@hidden>
- Date: Tue, 11 Mar 2003 12:04:01 -0800
- Thread-topic: Threads and messages
You don't need to require 10.2 if you don't want to.
Nathan Day wrote a cool sample called the NDRunLoopMessenger that allows you to
pass invokations between threads using a NSPort and NSPortMessage.
http://homepage.mac.com/nathan_day/
I would recommend checking that out first and if you would like to see another example
of that same type of calling mechanism you can take a look at my sample application that
does the same thing with notifications.
http://jrepp.com/src/AsyncNotificationsVer2.tgz
Or you can simply use the performSelector call in 10.2 and call it good ;)
-jake
http://jrepp.com/cocoabb/
-----Original Message-----
From: Marco Binder [
mailto:email@hidden]
Sent: Tuesday, March 11, 2003 6:29 AM
To: Jeff Disher; email@hidden
Cc: Cocoa List
Subject: Re: Threads and messages
Thanks for the pointer to performSelectorOnMainThread! I guess I bite
the bullet and make 10.2 a prerequisite. In my opinion, everyone should
own it anyways and its going to be a scientific app, so I hope 10.2 is
a good presumption.
Jeff, thanks for your additional suggestions. All of them sound very
reasonable and I m sure I ll apply them in one or the other project!
actually, I tried to do the GUI work in the secondary thread (right
now, its just reloading a NSTableView datasource and updating some
selection), but as I get more threads, the app used to crash with
signal 10 or 11, absolutely randomly. So I guess, I might want to
restrict the threaded work on ONLY the calculations.
Thanks,
Marco
>
Well, if you want an ugly hack you could use the
>
NSDistributedNotificationCenter but it is supposed to be slow since it
>
informs every thread in ever process on the machine what happened.
>
If your main thread can block while the others perform their
>
computation (probably not what you want) then it is pretty trivial to
>
synchronize with a NSLock.
>
If you only need 10.2 as a deployment platform you can look at the
>
method to post a notification on the main thread, it should do
>
exactly what you want.
>
Of course, you could also have the secondary threads perform the UI
>
update themselves before they die as long as you are careful.
>
Probably the best way, however, (if you need 10.1, that is) is to use
>
a NSMessagePort or something similar. I found that approach works
>
pretty well, personally, and it isn't as big as full-blown DO.
>
>
Hope that helps,
>
Jeff.
>
>
On Tuesday, March 11, 2003, at 08:36 AM, Marco Binder wrote:
>
>
> I have a couple of computational threads, that dont need to talk to
>
> the
>
> main thread. But: they should really inform the main threrad, when
>
> they
>
> are done and will exit. Is there another way of doing so rather than
>
> using DO?
>
>
>
> If the main thread registers for the threads notifications, the docs
>
> say, the notification will be processed from within the exiting
>
> thread-
>
> thats not what I want since I d have to do some GUI element update...
>
>
>
> Marco
>
>
>
>
>
> --
>
> |\ /| E-Mail: email@hidden WWW: www.marco-binder.de
>
> | \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
>
> | |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
>
> BINDER _____________________________________________________
>
> _______________________________________________
>
> 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.
>
>
>
>
>
Jeff Disher
>
President and Lead Developer of Spectral Class
>
Spectral Class: Shedding Light on Innovation
>
http://www.spectralclass.com/
>
_______________________________________________
>
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.
>
>
--
|\ /| E-Mail: email@hidden WWW: www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________
_______________________________________________
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.
_______________________________________________
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.