Re: Framework Initialize function delayed...
Re: Framework Initialize function delayed...
- Subject: Re: Framework Initialize function delayed...
- From: "rohit dhamija" <email@hidden>
- Date: Wed, 12 Apr 2006 14:44:52 +0530
I know both of the methods mentioned are not good enough. I tried find
document containing the desired info but could not find any...
Can you or anybody in this group provide link to the document containing
framework initialization loading info ?
RDH
On 4/12/06, Christian Stieber <email@hidden> wrote:
>
> At 13:52 12.04.2006 +0530, rohit dhamija wrote:
>
> >1. Add Sleep in my application code . sleep(1). So that when application
> >loads, the initialize routine should get enough time to complete its
> >processing
>
> Bad. It assumes the init is run on a different thread, and
> it assumes it completes within 1 second.
>
>
> >2. In framework, take a static variable isInitializationRoutineCompleted
> =
> >false, global. Set it to true at end of Initialization routine. And at
> start
> >of Getdata()
> >check
> >while(isInitializationRoutineCompleted == false){
> >return;
> >}
>
> Even worse. It again assumes the init is on another thread
> (which may or may not be the case, I don't know), and it
> eats CPU time while polling for the init to complete.
> At least add some short sleep() into the body of the while.
>
> [ As written it may not work at all, since the global var
> needs to be declared volatile in this case. If you call the
> sleep() then volatile is not necessary, unless the compiler
> knows about sleep() ]
>
> However, there are always better ways.
>
> First thing I would try is to not expose a function but
> a method --- maybe the auto-init thing only works with
> the objective-C runtime.
>
> If that doesn't work, check the framework loading docs.
> There should be some way for applications to detect
> when loading has completed.
>
> Only if that turns up nothing...
>
> *If* the init is on a different thread, you can setup a
> global condition mutex like this:
>
> NSConditionLock *Mutex;
> ...
> Mutex=[[NSConditionLock alloc] initWithCondition:0];
> Load Framework, init runs in a different thread
> [Mutex lockWhenCondition:1];
> [Mutex unlock]; [Mutex release];
>
> In your framework init, at the end you just do a
> [Mutex lock];
> [Mutex unlockWithCondition:1];
>
> This will ensure correct timing and not waste CPU, but
> it only works if the init runs on a separate thread. If
> the init is merely queued and runs as part of the main
> runloop it will block forever.
>
> If it's a delayed-in-runloop thing, the easiest way
> to deal with it is to have the framework init do
> some "[MainObject InitCompleted]" at the end, and
> have your main code do its stuff in there. This will
> not work in the threaded case, unless you like having
> your threads and method calls mixed up.
>
> Christian
>
>
--
Rohit Dhamija(M) 9818446545
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden