This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS: creating different task with same function

Other Parts Discussed in Thread: SYSBIOS

Tool/software: TI-RTOS

Hi all,

I have the following class, and any child of it can run provided that it implements the Run() function.

I had to attach static class function when creating task in sys/bios (same with posix API), thus I used the static

function trick. The problem with this approach is that all task essentially has same function to run, and while this was working

well  (I think it was accidentally), when I created  more child application crashed.

I believe there is a problem with task stacks,  but I dont know how to handle that.

========================================================================================================================

Class ActiveCls {
    private:
 
        Task_Params taskParams;
        Task_Handle taskLa;
        Error_Block eb;
 
    protected:
 
        void attach(void* (*tsk_fxn)(void* arg), int priority) {
 
            Error_init(&eb);
 
            Task_Params_init(&taskParams);
            taskParams.priority = priority;
            taskParams.stackSize = 0x100000;
            taskParams.arg0 = (UArg) this;
 
            taskLa = Task_create(ActiveCls::__run, &taskParams, &eb);
            if(taskLa == NULL)
            {
                System_printf("Task creation() failed!\n");
                BIOS_exit(0);
            }

/*     SAME HAPPENS WITH PTHREAD API- BUT WORKS WELL UNDER WINDOWS 7 !!    */
        }
 
 
        virtual void* Run() {
 
            Log(
                    "Warning.. Run() function is not implemented for this class.\n");
            return 0;
        }
 
        ActiveCls(int pri) {
            attach(&ActiveCls::run, pri);
        }
 
        ActiveCls() {
            Log("Warning.. Class priority is not set, defaulting to priority 1.\n");
            attach(&ActiveCls::run, 1);
        }
 
        static void __run(UArg a0, UArg a1) {
 
            ((ActiveCls*) a0)->Run();
        }
 
};


class AnExampleChild : public ActiveCls  {

public:
    void* Run()    {
    Log("Heyo!, I am running..\n")
    }
};

========================================================================================================================

sincerely,

napyonsen

  • Hi napyonsen,

    At first glance, I don't see anything wrong with the code you posted above. What device are you developing for? Can you post a screenshot of the output you get from the crash? Since you mentioned that creating a child caused the crash, I think might be running out of heap. The crash output helps determine what happened. Also, which compiler & SYSBIOS version are you using?

    Regards,
    -- Emmanuel
  • Hi Emmanuel,

    There is no heap crash, because I met the heap crash before and log messages indicates that if happens. I provided 64 mb heap. device is 6678 and bios version is 6.46.00.23. c6000 compiler is 8.1.1. Note that
    there is already copy assignment bug in this version.
    When I tried to debug kernel, I have seen that task creation uses Memory_alloc() in Pthread.c , thus increased the heap large enough, and putted a break there, and it is safe (I recompiled the kernel with -o 0).

    Moreover, when I create the task in the tradational way, in main() function, no crash happens. (I assigned exactly same child functions and priorities to them, also same stack memory, all same as in my first post).

    I am also attaching the posix version of the class  here -- 1323.ActiveCls.h (I tried other version to make sure it is not a posix api bug). But same thing happened.

    If you want I can add .pp file , too, to try it yourself.

    sincerely,

    napyonsen

  • hi Emmanuel,
    could you found something? or have any suggestions why this might happen?

    regards,
    mustafa
  • I am also attaching some captures for debugging.

    3580.bug.zip

  • I have found something strange not related to task creation, and oppened a new thread here :
    e2e.ti.com/.../571322