×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    26

    Cool RThread and stray signal

    Hi,

    I am having trouble detecting were stray signal come from. I am geting E32USER-CBASE 46 when thread finishes.
    Here is the code snippet:
    ...
    void CFtpService::ConstructL()
    {
    CActiveScheduler::Add(this);
    }
    void CFtpService::StartThread()
    {
    RThread thread;
    thread.Create(KFTPServiceName, (TThreadFunction)threadFunction,MAX_STACK_SIZE,NULL,this);
    thread.Logon(iStatus);
    thread.SetPriority(EPriorityNormal);
    thread.Resume();
    thread.Close();
    SetActive();
    }
    TInt CFtpService::threadFunction(TAny *aPtr)
    {
    CFtpService* ftpservice;
    ftpservice = (CFtpService *)aPtr;
    // Do some thread work here
    // ......
    return KErrNone;
    }
    void CFtpService::RunL()
    {
    TInt res = iStatus.Int();
    }
    ...

    So, I want to be notified via RunL when thread finish, but I am getting E32USER-CBASE 46 error.

    I am doing something wrong?

    Note: this is only code snippet and I really need thread here. I have several AO in main engine and this
    one thread is really hard to avoid.

    Thank you.

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

    Re: RThread and stray signal

    Thats the thing about programming in Symbian, everyone thinks they need threads but they don't....

    Code:
    RThread thread;
    thread.Create(KFTPServiceName, (TThreadFunction)threadFunction,MAX_STACK_SIZE,NULL,this);
    thread.Logon(iStatus);
    thread.SetPriority(EPriorityNormal);
    thread.Resume();
    thread.Close();
    .... the thread object is now dead and the iStatus is cancelled
    .... set active will have no effect
    SetActive();
    On another note, you probably can't share FTP services like this as each thread needs its own cleanup stack, trap harness and active scheduler.
    Objects cannot really be passed between threads.

    Active objects are specific to a thread, so the iStatus is actually referring to an object in the wrong thread context which is another error.

    If you need to share active objects between threads, you need to setup a trap harness, cleanup stack and active object for each thread (including the process thread), do not share classes that use handles, remember to block concurrent access to shared state.

    To complete cross thread calls, you need to pass the thread handle id to the other thread. Open an RThread local object using the handle and then complete the iStatus on that thread object (see RThread::RequestComplete)

    This will then signal the active scheduler in the other thread to tell it that a request has been signalled and look for the active object that has completed in the list of active objects.
    Download Symbian OS now! [url]http://developer.symbian.org[/url]

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    26

    Re: RThread and stray signal

    Thank you for replying.
    Now I am confused. You said that after thread.Close(); thread is dead and here is snippet from Fibonacci 2 example from SDK:

    // initiate a request
    void CFibonacciThreadHandler::CalculateFibonacci(TInt aIterations)
    {
    const TInt KHeapSize = 0x800 ;

    _LIT(KTxtFibRequested,"\nFibonacci requested ... ");
    iConsole->Printf(KTxtFibRequested);


    RThread thread ;

    // set up parameters to thread

    iFibonacciParameters.iVar1 = aIterations ;
    iFibonacciParameters.iVar2 = iFibonacciEngine ;

    // generate thread, leave if fails

    TInt result = thread.Create(KTxtFibThread,(TThreadFunction)FibonacciThread, KDefaultStackSize,
    KMinHeapSize, KHeapSize, &iFibonacciParameters, EOwnerThread) ;
    User::LeaveIfError(result) ;

    // log on to thread - sets iStatus to KRequestPending
    // requests notification of thread completion
    thread.Logon(iStatus) ;

    // give thread low priority
    thread.SetPriority(EPriorityMuchLess) ;

    // resume thread (wake it up sometime after this function returns)
    thread.Resume() ;

    thread.Close() ;

    // ensure scheduler checks status
    SetActive() ;

    _LIT(KTxtOK,"OK \n");
    iConsole->Printf(KTxtOK);
    }

    Anyway I tried following but still getting error:

    TInt CFtpService::threadFunction(TAny *aPtr)
    {
    CFtpService* ftpservice;
    ftpservice = (CFtpService *)aPtr;
    // Do some thread work here
    // ......
    RThread thread;
    thread.Open(ftpservice->iThreadId);
    TRequestStatus* status = &(ftpservice->iStatus);
    thread.RequestComplete(status,KErrNone);
    return KErrNone;
    }

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,752

    Re: RThread and stray signal

    What Fibonacci2 does is not nice, but might be OK: the thread does not die when the object is closed, and the address of the passed TRequestStatus variable is already forwarded to the "other side" (the kernel), so it is not lost either. RThread is not an IPC session, so Logon request may survive the Close.
    Actually I can not see any problematic part in your original post from this point of view (it is not clear why would it be a good idea accessing your AO from the other thread).
    Your 2nd attempt completes the request twice (explicit completion from your code in the secondary thread, and implicit completion when the thread exists because of the RThread::Logon), that is obviously a stray signal.
    Are you sure about that this particular piece of code gives raises the panic?
    If your code can be executed in the emulator, enable Just In Time debugging in the preferences, then the debugger will show where the code actually dies. You say you have several active objects, make sure that all of them is Add-ed and invokes SetActive.

  5. #5
    Registered User
    Join Date
    Jun 2004
    Posts
    26

    Re: RThread and stray signal

    Hi wizard_hu_,

    I think you misunderstood me. I am not accessing other AO's from the thread.
    Thread consists of while EOF loop and fills in engine's buffer with data which I lock with RMutex.
    I just want to be notified when my thread completes (reaches end of file).
    The problem is that I am getting E32USER-CBASE 46 after thread finishes.

    I just enabled Just in time debugging but debugger doesn't show me where code dies.

  6. #6
    Registered User
    Join Date
    Jun 2004
    Posts
    26

    Thumbs up Re: RThread and stray signal (SOLVED)

    Problem Solved !!!

    The problem was that I was starting thread from the class which was defined locally, so after this function
    completes class was out of the scope and there was a reason for stray signal.

    For all of you who need threads (although everything can be done without them ) here is very good document:

    http://wiki.forum.nokia.com/index.ph...0867_-_RThread

Posting Permissions

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