Re: Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop?
Re: Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop?
- Subject: Re: Does initWithHTML:dataUsingEncoding:documentAttributes: run an event loop?
- From: Jean Suisse <email@hidden>
- Date: Wed, 15 May 2013 17:17:51 +0200
Right. I dispatch the block on the main thread to solve the reentrancy issues as stated below. The serial queue is involved elsewhere.
On 15 mai 2013, at 16:12, Ken Thomases wrote:
> On May 15, 2013, at 8:58 AM, Jean Suisse wrote:
>
>> Thanks for your replies.
>> Unfortunately, I can't easily avoid initWithHTML:dataUsingEncoding:documentAttributes:
>> But I can postpone it long enough to move its execution to an other thread (serial dispatch queue).
>> That solves the issue.
>
> I doubt it will. If that method is invoked from a background thread, it will shunt the work to the main thread anyway. In other words, it always does its work on the main thread.
>
> Regards,
> Ken
>
On 8 may 2013, at 01:06, Jean Suisse wrote:
> Thanks for this suggestion. Actually, once identified, I fixed the bug fairly quickly by postponing the task (dispatched a block on the main thread for that).
> The bug was caused by two successive events arriving in a short timeframe so that the stack looked like that:
>
> 0 my callback
> 1 __CFSocketPerformV0
> ------------------------------------
> 9 initWithHTML:dataUsingEncoding:documentAttributes:
> 10 my function 1
> 11 my function 2
> 12 my callback
> 13 __CFSocketPerformV0
> -----------------------------------
> 23 NSApplicationMain
> 24 main
> 25 Start
>
> and my callback never was designed to be called a second time before the first call was finished. Dispatching a block to handle my function 1 fixed the issue.
> However, information about initWithHTML:dataUsingEncoding:documentAttributes: running an event loop could be worth mentioning in the docs…
>
> Jean
>
> On 8 mai 2013, at 00:52, Ken Thomases wrote:
>
>> On May 7, 2013, at 5:37 PM, Jean Suisse wrote:
>>
>>> By any chance, could a call to [[NSAttributedString alloc] initWithHTML:dataUsingEncoding:documentAttributes:] lead to the event loop being run before the call returns?
>>
>> Yes, it can. Under the hood, NSAttributedString is using WebKit for HTML rendering. In part that means that, when invoked from a background thread, it has to shunt the work to the main thread. But it also means the main thread may have to run the run loop during the call. It's a nuisance, but it's necessary since HTML can have references to external resources that need to be loaded.
>>
>> Consider the other method, -[NSAttributedString initWithHTML:options:documentAttributes:] and its options dictionary, which can have keys like NSTimeoutDocumentOption and NSWebResourceLoadDelegateDocumentOption. Those imply a pretty involved process under the hood. I'm fairly certain that this method is used for the implementation of the method you're using.
>>
>> You may be able to use those options to minimize the use of the run loop, but probably not eliminate it.
>>
>> Regards,
>> Ken
>>
>
> -----------
> Jean Suisse
> Institut de Chimie Moléculaire de l’Université de Bourgogne
> (ICMUB) — UMR 6302
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden