Re: Follow-up: Cocoa thread-safety
Re: Follow-up: Cocoa thread-safety
- Subject: Re: Follow-up: Cocoa thread-safety
- From: OS X AIBO <email@hidden>
- Date: Fri, 25 Oct 2002 22:19:47 -0700 (PDT)
Hmm. I don't know what the best solution is, but this is what came to
mind.
You want the main thread to remain idle unless there is something for
the user to see or the user performs some action. Since the main thread
is good at waiting for events, why not send it an event from your
worker thread once it has received data over the net.
Check out NSApplication's public void postEvent( NSEvent anEvent,
boolean flag)
"Adds anEvent to the receiver's event queue. If flag is true, the
event is added to the front of the queue, otherwise the event is added
to the back of the queue.
This method can also be called in subthreads. Events posted in
subthreads bubble up in the main thread event queue."
Then check out NSEvent's "Other Events" topic.
"... Of the three miscellaneous event types, only NSApplicationDefined
is of real use to application programs. It allows the application to
generate totally custom events and insert them into the event queue.
Each such event can have a subtype and two additional codes to
differentiate it from others.
otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2
creates one of these events, and the subtype, data1, and data2 methods
return the information specific to these events."
Let me know if that works out. I could end up using this myself.
Cheers,
--Dan
--- Steve Klingsporn <email@hidden> wrote:
>
The following is written in the 10.2 Cocoa release notes:
>
>
New methods for performing selectors on the main thread
>
>
Sometimes a background thread must have the main thread perform some
>
work on its behalf. These are often UI-related things, like updating
>
a
>
window's displayed state. Two new methods on NSObject, declared in
>
<Foundation/NSThread.h>, have been added in 10.2.
>
>
- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg
>
>
waitUntilDone:(BOOL)wait modes:(NSArray *)array;
>
- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg
>
>
waitUntilDone:(BOOL)wait;
>
>
>
Unfortunately, NSThread is not available from Java, nor do these
>
methods seem to be relocated as the Java counterparts often are. I
>
suppose it might be possible to write some code that uses JNI or the
>
Java Bridge to do this, but this violates my desire to keep
>
everything
>
Java. My timer approach works, but using 4% of the CPU to run a
>
timer
>
4 times a second seems a bit extreme to me.
>
>
Any help would be appreciated. Thank you.
>
>
Steve
>
_______________________________________________
>
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.
Y! Web Hosting - Let the expert host your web site
http://webhosting.yahoo.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.