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 19/10/2005 09:00 Pm, Scott Fraser wrote:

> 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"?
> 
> You can create your own event types, and post them directly to the
> Carbon Event queue of the secondary thread.

Yep, correct so far.

> You can install handlers
> on the event dispatcher for that thread, using GetEventDispatcherTarget
> to get the event target for that thread.

Is event dispatcher per thread?! I don't see this documented.
[InstallEventHandler is also not thread safe, but this is less
a show stopper because it can be worked around by calling it
on the main thread.]

> Then in the secondary thread,
> ReceiveNextEvent, and then SendEventToEventTarget.  Maybe that's a
> little roundabout, but it works.

Neither ReceiveNextEvent nor SendEventToEventTarget are thread
safe, see below.

> See:
> http://developer.apple.com/documentation/Carbon/Conceptual/
> Carbon_Event_Manager/index.html
> ....
> 
> Oops!  Once you get to the Carbon Event Manager index, try:
> 
> Carbon Event Manager Tasks -> Processing Events Manually  (page 40 in
> the PDF version (2005-07-07)
> Carbon Event Manager Tasks -> Creating Your Own Events   (page 42)
> Carbon Event Manager Tasks -> Carbon Events in Multiple Threads  (pg 43)

E.g. this (see the quote below) and this is something I don't
understand, because it is in direct contradiction with the "not
thread safe" marks on these APIs:

#After first creating the thread, ....
#It can then call ReceiveNextEvent, blocking until someone sends
#it an event. 

Hmm... ReceiveNextEvent is also marked "not thread safe" which
is a show stopper as I see it. Is it just marked incorrectly?
Same question (potentially leading to a different answer) about
SendEventToEventTarget; is it just marked incorrectly?

Mike

 _______________________________________________
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: Scott Fraser <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.