×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    197

    Question Main thread gets called too late,why?

    Hi there,

    As http://discussion.forum.nokia.com/fo...d.php?t=101999 states,
    I first get the main thread handle in main thread like the following

    Code:
    // in main thread
    iMainThread = RThread();
    and then, in my secondary thread,I duplicated main thread and call main thread's RequestComplete()like the following,
    Code:
    // in secondary thread
    RThread thread;
    thread.Duplicate( iMainThread ); //Is it necessary to do like this?
    thread.RequestComplete(status, KErrNone);
    //But after I called this function, the RunL() of the 
    //active object to which status belongs does not get called immediately
    // in main thread,why??
    //As I knew that I in main thread called secondary thread's RequestComplete(),that related RunL() in
    // secondary thread got called immediately,this happened in my app.
    Where I did wrong?
    Please help.

    Thanks in advance.
    //---------------------------------------------------------------------------------
    Stand on the shoulders of the Great and build a better world.
    //---------------------------------------------------------------------------------

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,572

    Re: Main thread gets called too late,why?

    There is no such thing as "immediately". Asynchronous IPC is what you are doing, where "asynchronous" is the keyword.

  3. #3
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: Main thread gets called too late,why?

    If you need to synchronize thread creation you can use RThread::Rendezvous and User::WaitForRequest. Since the Thread startup takes little time it is appropriate in this case to use User::WaitForRequest. Remember however User::WaitForRequest blocks the UI until the thread has started.

    I would hasten to add that you expectation of instant thread synchronization is optimistic on a single processor device.
    Download Symbian OS now! [url]http://developer.symbian.org[/url]

  4. #4
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    197

    Post Re: Main thread gets called too late,why?

    Quote Originally Posted by wizard_hu_ View Post
    There is no such thing as "immediately". Asynchronous IPC is what you are doing, where "asynchronous" is the keyword.

    Yea, you are right,no such thing,
    thanks.

    Meanwhile,what I meant by "immediately" is that While I was in debug situation,
    after I called RThread::RequestComplete(), I can (almost immediately) see that the break point of RunL() in secondary thread be hit,and then I could go there to debug line by line.

    But when I called main thread's RequestComplete(), the related break point of the RunL() in main thread was not hit,
    some time later (too late for my mission in main thread),that RunL() in main thread was called.

    Please help.
    //---------------------------------------------------------------------------------
    Stand on the shoulders of the Great and build a better world.
    //---------------------------------------------------------------------------------

  5. #5
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    197

    Post Re: Main thread gets called too late,why?

    Quote Originally Posted by Paul.Todd View Post
    If you need to synchronize thread creation you can use RThread::Rendezvous and User::WaitForRequest. Since the Thread startup takes little time it is appropriate in this case to use User::WaitForRequest. Remember however User::WaitForRequest blocks the UI until the thread has started.

    I would hasten to add that you expectation of instant thread synchronization is optimistic on a single processor device.

    Thanks.But I dont know how to use RThread::Rendezvous...

    It is not about synchronizing thread creation,
    it is about the responsiveness of main thread after secondary thread sigals the completion of the request of main thread.
    Last edited by leejx; 2009-10-20 at 10:27.
    //---------------------------------------------------------------------------------
    Stand on the shoulders of the Great and build a better world.
    //---------------------------------------------------------------------------------

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,572

    Re: Main thread gets called too late,why?

    Note that it also matters if your main thread is doing something. Active objects use non-pre-emptive scheduling, so the RunL of your handler for the secondary thread will not run until the currently executed RunL returns. Active objects also have priorities, so it can happen that some other AO runs first - you can try setting some higher priority for your handler AO. Threads/processes also have priorities by the way.

  7. #7
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    197

    Post Re: Main thread gets called too late,why?

    Quote Originally Posted by wizard_hu_ View Post
    Note that it also matters if your main thread is doing something. Active objects use non-pre-emptive scheduling, so the RunL of your handler for the secondary thread will not run until the currently executed RunL returns. Active objects also have priorities, so it can happen that some other AO runs first - you can try setting some higher priority for your handler AO. Threads/processes also have priorities by the way.

    I have used RMutex for sync sake,
    and about the priorities of the AO,thread and process, I did have set it high enough.


    As to this,
    Quote Originally Posted by wizard_hu_ View Post
    so the RunL of your handler for the secondary thread will not run until the currently executed RunL returns.
    there is no such situation in my app,
    and the RunL() of AO in main thread should have nothing to do with those RunL() in secondary thread.

    Thanks all the same.
    //---------------------------------------------------------------------------------
    Stand on the shoulders of the Great and build a better world.
    //---------------------------------------------------------------------------------

  8. #8
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,572

    Re: Main thread gets called too late,why?

    Quote Originally Posted by leejx View Post
    I have used RMutex for sync sake,
    and about the priorities of the AO,thread and process, I did have set it high enough.
    Oh, our beloved RMutex is back.
    and the RunL() of AO in main thread should have nothing to do with those RunL() in secondary thread.
    I was talking about the situation if a RunL in your 'main' thread is already running. http://wiki.forum.nokia.com/index.php/Active_Scheduler

Similar Threads

  1. S60 5th Edition emulator startup problem
    By gopitek in forum Symbian
    Replies: 2
    Last Post: 2010-09-08, 08:05
  2. S60 5th ed emulator startup failed
    By hony in forum Symbian Tools & SDKs
    Replies: 8
    Last Post: 2009-08-11, 21:12
  3. Why don't S60 emulator loading?
    By K.John in forum Feedback - Nokia Developer Services & Infrastructure
    Replies: 9
    Last Post: 2009-08-11, 11:03
  4. Replies: 14
    Last Post: 2009-03-02, 16:56
  5. emulator startup failed
    By hony in forum Symbian User Interface
    Replies: 3
    Last Post: 2008-11-11, 06:07

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •