Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Not thread safe events?



On Oct 18, 2005, at 11:23 PM, Mike Kluev wrote:

On Tue, 18 Oct 2005 14:55:45, Scott Fraser <email@hidden> wrote:

On Oct 18, 2005, at 12:02 PM, George Warner wrote:

You can post events from a secondary thread but currently that's about
it.


All handler should run on the main thread.

Surely you meant that all handlers for "UI events" should run on the main thread. Otherwise it wouldn't make any sense to be able to post an event to the event queue of a secondary thread.

Hmm, maybe it doesn't currently make any sense? How'd you obtain event target of a "non UI element" (whatever this means) to be able to InstallEventHandler on it? Ok, probably by calling HIObjectGetEventTarget on some ad hoc hi object created for the purpose of having the required EventTargetRef (HIObjectCreate, HIObjectGetEventTarget and InstallEventHandler will have to be called on the main thread - because they are not thread safe - but that's doable). But then, in order to call your event handler on the secondary thread, you or the system will have to use SendEventToEventTarget in the secondary thread and SendEventToEventTarget is not thread safe. Even ReceiveNextEvent is not thread safe to receive events manually without dispatching them to handlers. Makes me wonder what is the purpose of per-thread event queuesthen at all... Or is this just another instance that by "not thread safe" they don't mean "not safe to call on secondary threads" but something different like "don't call from more than one thread on the same eventRef"?

Mike

You can create your own event types, and post them directly to the Carbon Event queue of the secondary thread. You can install handlers on the event dispatcher for that thread, using GetEventDispatcherTarget to get the event target for that thread. Then in the secondary thread, ReceiveNextEvent, and then SendEventToEventTarget. Maybe that's a little roundabout, but it works.


See:
http://developer.apple.com/documentation/Carbon/Conceptual/ Carbon_Event_Manager/index.html


http://developer.apple.com/documentation/Carbon/Conceptual/ Carbon_Event_Manager/index.html

http://developer.apple.com/documentation/Carbon/Conceptual/ Carbon_Event_Manager/index.html

Scott
-----
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: Not thread safe events? (From: Mike Kluev <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.