How to keep a spawned task alive until delete - VxWorks

This is a discussion on How to keep a spawned task alive until delete - VxWorks ; I have spawned a task. The task is spawned and I could see some printf() inside the spawned task. But I can't see that task in the task list when I type "i" on the sonsole prompt. Here is the ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: How to keep a spawned task alive until delete

  1. How to keep a spawned task alive until delete

    I have spawned a task. The task is spawned and I could see some
    printf() inside the spawned task. But I can't see that task in the task
    list when I type "i" on the sonsole prompt.

    Here is the skeleton of my code that I used to spawn that task:

    /*************************
    int myMainFunc()
    {
    int spawnedTaskID;
    if (spawnedTaskID = taskSpawn("MYTASK", 100, 0, 20000, (FUNCPTR)
    myTask, 0, 2, 0,0,0,0,0,0,0,0) == ERROR)
    {
    printf("The task spawn FAILED !\n");
    return error;
    }
    else
    {
    printf("The task spawn SUCCESS !\n");
    }

    return OK;
    }

    void myTask(int param1, int param2)
    {

    printf("Hello World !");

    /* Note, here I didn't use any return */

    }
    **********************/

    Note that I could see "Hello World" printed on the console. But I don't
    see the task "MYTASK" in the task list when I type "i" on the console.
    I tried on both target and tornado shell, MYTASK is missing everywhere.

    My guess: this task get suspended (or deleted) right after spawned. How
    could I keep it alive until explicitly I delete this task ?

    Please help.


  2. Re: How to keep a spawned task alive until delete

    when it falls off the end, it automatially deletes itself. Use a while
    loop to keep it from falling out, but you will also have to block the task
    periodically (e.g. by use of a semaphore or taskDelay) to let other tasks
    run.

    David

    akarui.tomodachi@gmail.com wrote:

    > I have spawned a task. The task is spawned and I could see some
    > printf() inside the spawned task. But I can't see that task in the task
    > list when I type "i" on the sonsole prompt.
    >
    > Here is the skeleton of my code that I used to spawn that task:
    >
    > /*************************
    > int myMainFunc()
    > {
    > int spawnedTaskID;
    > if (spawnedTaskID = taskSpawn("MYTASK", 100, 0, 20000, (FUNCPTR)
    > myTask, 0, 2, 0,0,0,0,0,0,0,0) == ERROR)
    > {
    > printf("The task spawn FAILED !\n");
    > return error;
    > }
    > else
    > {
    > printf("The task spawn SUCCESS !\n");
    > }
    >
    > return OK;
    > }
    >
    > void myTask(int param1, int param2)
    > {
    >
    > printf("Hello World !");
    >
    > /* Note, here I didn't use any return */
    >
    > }
    > **********************/
    >
    > Note that I could see "Hello World" printed on the console. But I don't
    > see the task "MYTASK" in the task list when I type "i" on the console.
    > I tried on both target and tornado shell, MYTASK is missing everywhere.
    >
    > My guess: this task get suspended (or deleted) right after spawned. How
    > could I keep it alive until explicitly I delete this task ?
    >
    > Please help.



  3. Re: How to keep a spawned task alive until delete

    Thanks David for your solution.
    I have few more questions now....
    In my application, there is no other tasks to be spawned. All are
    simple function calls. This task is spawned because another external
    application needs my application's ID to send some signal (SIGPIPE)
    asynchronously to me, which in turn invokes a SIGPIPE Handler function
    within my application. However, if I block the task periodically, do
    you think that would be a problem ?

    Also please show me exactly where to put the taskDelay() or while loop
    in my code.

    I am still confused :-(


  4. Re: How to keep a spawned task alive until delete

    hi akarui,
    when you type i at the shell prompt it shows you the list
    of tasks that are currently available in the system.RULE:Any task will
    run as long as it has instructions to execute.If your task runs out of
    instructions,then its work is over and it is deleted.So once you get
    back the shell prompt your task has finished its work and hence no more
    available in the system.To make your task still be available make it
    execute ,say an infinite loop.Hence give a while(1); loop as the last
    statement of your task.Obviously it won't exit.Then if you type i at
    the shell,you can find it in the list.But for that shell should get its
    chance to accept input as it is PBPS scheduling by default.Hence make
    sure the task alone won't eat up the cpu time due to its high
    priority.Hence the better solution is:
    while(1)
    {
    taskDelay(3);
    }
    Making it sleep for 3 ticks in an infinite loop.

    Coming to the second issue.The approach of blocking it temp. won't
    create any problem provided you use queued signal facility using POSIX
    signal handling.

    cheers-
    kaushal.


  5. Re: How to keep a spawned task alive until delete

    According to suggestions, I put the following statements (//added
    statement) in my function, myTask() and I could see that my task is
    alive. I am happy and everything was working fine so far.

    But, I found a new problem while running a separate function, which is
    simply a function without any relation to this task myTask(). That
    function uses "strcpy" command to write some strings to some char
    buffers.

    When I run that function, it gives exception of "data access". My guess
    is that, probably, that spawned task "myTask" is creating some problem.
    Problem only encountered when "strcpy" is attempted to execute.

    Can you please give some clue what might cause the this problem ?

    /*************************
    int myMainFunc()
    {
    int spawnedTaskID;
    if (spawnedTaskID = taskSpawn("MYTASK", 100, 0, 20000, (FUNCPTR)
    myTask, 0, 2, 0,0,0,0,0,0,0,0) == ERROR)
    {
    printf("The task spawn FAILED !\n");
    return error;
    }
    else
    {
    printf("The task spawn SUCCESS !\n");
    }

    return OK;

    }

    void myTask(int param1, int param2)
    {

    SEM_ID mySemID = semBCreate(SEM_Q_FIFO, SEM_FULL); // added
    statement

    printf("Hello World !");

    semTake(mySemID,WAIT_FOREVER); // added statement
    semGive(mySemID); // added statement

    /* Note, here I didn't use any return */

    }

    **********************/


+ Reply to Thread