×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    61

    How to handle CActiveScheduler::Start() event?

    I write an active class with internal worker thread. So I need to perform synchronously an instance initialization. In ConstructL I have:
    Code:
    // create a worker thread and run it
    User::LeaveIfError(iInnerThread.Create(
    innerThreadName, ThreadFunction, KDefaultStackSize, 0, this));
    iInnerThread.Resume();
    
    // wait for CActiveScheduler::Start
    ???
    In 2nd edition I can handle this by implementing interface with CActiveScheduler::OnStarting, but it's not compatible with 3nd edition. This problem I already faced with in previous version of my class. Then I was forced to use CActiveSchedulerWait (by spinlocking IsStarted). Is there a more elegant way without using CActiveSchedulerWait? Thank you.

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

    Re: How to handle CActiveScheduler::Start() event?

    I still do not understand the use case: since the ex-OnStarting method happens/happened in the same thread, I can not see for what you have used it, and why.

  3. #3
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    61

    Re: How to handle CActiveScheduler::Start() event?

    As I mentioned I need a thread safe file class (as you know, RFile can work only inside thread where it was constructed). The active object has an internal thread to perform file operations. The Symbian generic file interface has many synchronous methods (which I try to implement). So I need to implement synchronous functionality by asynchronous mechanism of active objects, therefore I need to use synchronization primitives - after sending request I must block myself until operation is finished (to achieve this I use fast user-mode critical sections). In instance construction stage (ConstructL) I cannot return until I know that CActiveScheduler::Start was invoked (if it wasn't - the user can invoke some method before it will happen - so that method will do nothing).

  4. #4
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: How to handle CActiveScheduler::Start() event?

    I don't understand the need to create a thread within an active object? It seems to contradict the very purpose of active objects and threads. If the reason is something to do with "needing a thread safe file class" what do you mean?

    All this talk of active objects, threads, blocking yourself, using critical sections. I might be wrong and don't know what you want to achive but it strikes me as potentially being way over the top. Far too much complextity.

    What is it you want to do exactly that is making you create threads and critical sections?

  5. #5
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    61

    Re: How to handle CActiveScheduler::Start() event?

    If the reason is something to do with "needing a thread safe file class" what do you mean?
    You can't create RFile in one thread and use it in another. That's the problem. To solve it you need to write class which accept requests from every thread and performes the needed actions in separated thread of it's own.

  6. #6
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: How to handle CActiveScheduler::Start() event?

    1) Ignorning anything to do with RFiles, do you *need* to create multiple threads? i.e. do you *need* pre-emptive multitasking? If not then one thread with multiple active objects should suffice.

    2) If you really must have thread, why cannot one thread call RFile::Open(filename) and another file call RFile::Open(filename). Each thread will have different RFile classes but the underlying file being accessed is the same. Do you need multiple simultaneous read/write access to a file?

    3) If you really need some object to manage access to the file and co-ordinate things, perhaps a server is cleaner.
    Also you could look at RFile::TransferToClient() and AdoptFromServer() etc. to see if you can use those.

    I feel if you're using a combination of active objects and threads and critical sections and are not experienced with Symbian it is a recipe for a lot of frustration.
    Last edited by hotcheese; 2008-06-03 at 22:10.

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

    Re: How to handle CActiveScheduler::Start() event?

    Perhaps I understand - at least partially.
    You can replace OnStarting with adding and User::RequestComplete-ing an active object. So it is going to be invoked by the Active Scheduler as soon as it gets started.
    And RThread::Rendezvous can help you in this case:
    Code:
    iInnerThread.Rendezvous(somestatus);
    iInnerThread.Resume();
    User::WaitForRequest(somestatus);
    in the outer thread. And
    Code:
    void COnStartingAO::RunL()
    {
        RThread().Rendezvous(KErrNone);
    }
    in the inner thread.

    It can work, though I still can not see the goal.

    EDIT: I actually started writing this after #3, without seing #4-6... :-S
    Last edited by wizard_hu_; 2008-06-03 at 22:13.

  8. #8
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    61

    Re: How to handle CActiveScheduler::Start() event?

    Yes, now I'm agree with you – my problem can be solved by much more simple design. In my case I don’t really need threads and synchronization (I’m just not really familiar with active objects – the complexity described above was because of this fact). Thank you all.

Similar Threads

  1. handle list box event in Carbide .
    By ankushbabrekar in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2007-04-10, 06:43
  2. CLogEvent problem
    By silviuccia in forum Symbian
    Replies: 2
    Last Post: 2006-12-22, 15:28
  3. Handle Event of CEikCommandButton
    By calculator420 in forum Symbian User Interface
    Replies: 1
    Last Post: 2006-07-14, 13:39
  4. handle game event in j2me
    By wmchan78 in forum Mobile Java General
    Replies: 2
    Last Post: 2006-03-04, 03:56
  5. How I Can handle event in an activ loop
    By netrixe in forum Symbian
    Replies: 1
    Last Post: 2003-11-26, 02:42

Posting Permissions

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