×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    17

    RThread - parameter to the thread function

    hi folks,
    how to pass a parameter to the thread function?
    the thread function panics with "KERN-EXEC 0", when call some methods or get variables from parameter class.
    wat is wrong in this code?
    *******************************
    void MyApp::StartThread()
    {
    CSomething* pSomeObject; // parameter class
    pSomeObject = new (ELeave) CSomething;
    pSomeObject->ConstructL();

    const TUint KThreadMinHeapSize = 0x1000;
    const TUint KThreadMaxHeapSize = 0x10000;
    RThread myThread;
    User::LeaveIfError( myThread.Create(
    _L("MyThread&quot,
    MyApp::ThreadFunction,
    KDefaultStackSize,
    KThreadMinHeapSize,
    KThreadMaxHeapSize,
    pSomeObject, /*pointer to data to be passed as a parameter*/
    EOwnerProcess) );

    myThread.SetPriority(EPriorityNormal);
    myThread.Resume(); //start the thread
    }

    TInt MyApp::ThreadFunction( TAny* aParam )
    {
    // cast the parameter pointer
    CSomething* pSomeObj = (CSomething*)aParam;
    ...

    // !! PANICS HERE !! KERN-EXEC 0
    pSomeObj->SomeGetSetFunction();
    //why?

    ...

    return KErrNone ;
    }
    *******************************

    thank you in advance

    regards
    eddy

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    55

    RE: RThread - parameter to the thread function

    Hi Eddy,

    You have more errors in the code:
    1. Before pSomeObject->ConstructL(); you need to put the pSomeObject pointer to the cleanup stack, else memory leak may occure.
    2. The passed function is a class function. This means that the first parameter to this function is always the 'this' (pointer to the class). So if your function is called, the this==pSomeObject and the parameter 'passed' is a 'random' piece of the stack.

    To solve the 2. problem pass a global function. This global function than may call your class' function with requred parameters.

    Brg,
    Szabolcs Tolnai

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    17

    RE: RThread - parameter to the thread function

    hello Szabolcs,

    could you post an example code for the 2.problem, please?

    thanx

Posting Permissions

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