×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Dec 2004
    Location
    Mumbai
    Posts
    67

    Thread function not being called

    Hi All,

    I'm trying to implement a bacgkroud processing using RThread. In one of my clases.

    I call the createthread method with the name of the threadfuntion which is a static method, which takes tAny*. And am also passing the "this" pointer to the createthread object.

    And then call thread.resume()

    Now when I rup the app, I can see that the thread is being created, but it does not call the thread function.

    Here is my code: please let me know what is the issue with it

    //////////////////////////////////////////////////////////////
    //// start a diff thread
    iThread = new(ELeave)RThread();
    TInt res = iThread->Create(_L("CNet Thread"), ThreadEntryPoint,KDefaultStackSize, this, NULL, NULL, KMinHeapSize, KMinHeapSize, EOwnerProcess );

    #ifdef _DEBUG
    iLog.WriteFormat(_L("After creating the thread:[%d]"), res);
    #endif

    if (KErrNone!=res)
    {// Complete the caller immediately
    //User::RequestComplete(iCaller, res);
    }
    else
    {// Set active; resume new thread to make the synchronous call
    // (Change the priority of the thread here if required)
    // Set the caller and ourselves to KRequestPending
    // so the active scheduler notifies on completion


    #ifdef _DEBUG
    iLog.Write(_L("Starting the thread "));
    #endif

    //*iCaller = KRequestPending;
    //iStatus = KRequestPending;
    //SetActive();

    #ifdef _DEBUG
    iLog.Write(_L("After calling setactive"));
    #endif

    //iThread->Logon(iStatus); // Request notification when thread dies
    iThread->Resume(); // Start the thread

    #ifdef _DEBUG
    iLog.Write(_L("After Starting the thread"));
    #endif

    }
    ////////////////////////////////////////////////////////////
    //// end of thread



    TInt CCNetPlugin::ThreadEntryPoint(TAny* aParameters)
    {

    // Perform a long synchronous task e.g. a lengthy calculation

    CCNetPlugin* pThis = (CCNetPlugin*)aParameters;

    #ifdef _DEBUG
    pThis->iLog.Write(_L("Thread entry point"));

    if(pThis)
    {
    pThis->iLog.Write(_L("Pthis is not NULL"));
    }
    else
    {
    pThis->iLog.Write(_L("Pthis is NULL"));
    }
    #endif

    return(KErrNone);
    }

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

    Re: Thread function not being called

    There are a number of issues with the code.

    Are you sure your thread is actually being resumed? If the thread fails to create you will not be notified

    I am assuming iLog is a R type object that accesses a file. You cannot do this as RHandles are not sharable across threads without a lot of work.

    It also looks like your thread will run once (You need some kind of look to keep the processing going) so it might just be executing really fast?

  3. #3
    Regular Contributor
    Join Date
    Dec 2004
    Location
    Mumbai
    Posts
    67

    Re: Thread function not being called

    Hi Thanx for the prompt reply. The resume is being called on the thread. Also when I check the return value create method it is Kerrnone.

    With regard to iLog, you are right file handles cannot be shared, so it might not be giving any log statements. But in case I call thread.kill or user::Exit within the thread function, the thread must exit right?

    But that does not happen too implying that the threadfunction is not being called

    Kamal

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

    Re: Thread function not being called

    So have you actually set a breakpoint in the thread function ThreadEntryPoint and seen if it is actually called, preferably on the pThis line?

  5. #5
    Regular Contributor
    Join Date
    Dec 2004
    Location
    Mumbai
    Posts
    67

    Re: Thread function not being called

    I've modified the Threadfunction to look like this

    TInt CMyClass::ThreadFunction(TAny* aParameter)
    {
    RThread.Kill(0);
    }

    Now when the thread runs and this thread function is called the thread should die, but the thread still exists, I checked it using the Task Spy application.

    Kamal

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

    Re: Thread function not being called

    Why don't you try walking before running, debug the code on the emulator first to see what it going on.

    You do not need to kill the thread, just let the thread function end.

    I suspect there is something more going on with your application than this code would indicate.

    The reason why the thread appears to be still alive is that the kernal still has the object open as you did not close the handle after resuming the thread.

Similar Threads

  1. Replies: 2
    Last Post: 2004-01-14, 15:58
  2. Replies: 4
    Last Post: 2004-01-09, 07:45
  3. Cannot compile SDK's examples for 7650 platform...
    By midletsoft in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2003-08-12, 19:11
  4. Can't start thread function
    By liuhoihing in forum Symbian
    Replies: 0
    Last Post: 2003-05-05, 06:35
  5. Problem with Nokia D211 Linux Drivers
    By fiveam in forum Multimodecards
    Replies: 1
    Last Post: 1970-01-01, 02:00

Posting Permissions

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