How to do multi-tasking in VxWorks ?? - VxWorks

This is a discussion on How to do multi-tasking in VxWorks ?? - VxWorks ; Hi, I am writing one sample code as below in VxWorks: void test() { printf("\n test..\n"); } void test_task() { taskSpawn("test", 100, 0, 16*1024, (FUNCPTR)test, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); } If I am calling ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: How to do multi-tasking in VxWorks ??

  1. How to do multi-tasking in VxWorks ??

    Hi,

    I am writing one sample code as below in VxWorks:

    void test()
    {
    printf("\n test..\n");
    }

    void test_task()
    {
    taskSpawn("test", 100, 0, 16*1024, (FUNCPTR)test, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0);
    }

    If I am calling "test_task" multiple times in the target shell like
    below :

    -> sp test_task
    task spawned: id = 3d94940, name = s1u0
    value = 64571712 = 0x3d94940
    ->sp test_task
    task spawned: id = 3d9d940, name = s1u1
    value = 64571712 = 0x3d94940
    ->sp test_task
    task spawned: id = 3d9d940, name = s1u2
    value = 64571712 = 0x3d94940
    ->sp test_task
    task spawned: id = 3d9d940, name = s1u3
    value = 64571712 = 0x3d94940

    By calling this way, will it be multi-tasking?

    Please clarify...

    Regards
    Satish.

  2. Re: How to do multi-tasking in VxWorks ??

    Hello,

    VxWorks is multi-tasking by nature so, yes, if you run code via the
    'sp' command or the 'taskSpawn()' API this code will be executed by a
    task. Note that, in your example above you are asking the shell to
    spawn a task ('sp' command), this task executes the test_task()
    routine which in turn spawns a task executing the routine test(). So
    you get two tasks spawned to execute the printf() call. You could also
    have executed test() as a task directly by typing: sp test. Or you
    could have simply called test_task() from the shell: -> test_task

    Hope this helps,

    --
    PAD

  3. Re: How to do multi-tasking in VxWorks ??

    On 28 Gen, 16:32, satish....@gmail.com wrote:
    > Hi,
    >
    > I am writing one sample code as below in VxWorks:
    >
    > void test()
    > {
    > * * * printf("\n test..\n");
    >
    > }
    >
    > void test_task()
    > {
    > * * * *taskSpawn("test", 100, 0, 16*1024, (FUNCPTR)test, 0, 0, 0, 0,
    > 0, 0, 0, 0, 0, 0);
    >
    > }
    >
    > If I am calling "test_task" multiple times in the target shell like
    > below :
    >
    > -> sp test_task
    > task spawned: id = 3d94940, name = s1u0
    > value = 64571712 = 0x3d94940
    > ->sp test_task
    > task spawned: id = 3d9d940, name = s1u1
    > value = 64571712 = 0x3d94940
    > ->sp test_task
    > task spawned: id = 3d9d940, name = s1u2
    > value = 64571712 = 0x3d94940
    > ->sp test_task
    > task spawned: id = 3d9d940, name = s1u3
    > value = 64571712 = 0x3d94940
    >
    > By calling this way, will it be multi-tasking?
    >
    > Please clarify...
    >
    > Regards
    > Satish.


    Sure it will... In your simple example you are calling the "test"
    function each time in its own context. Your test function returns
    immediately after the printf, so as soon as you spawn the second task,
    the first will already be terminated

    If you modify your test function to be a forever loop, say printing
    ("This is me %d\n", taskIdSelf()) each second, you will see that the
    tasks will run concurrently, each of them printing its own Task Id.


  4. Re: How to do multi-tasking in VxWorks ??

    On 29 Gen, 09:10, "benelli.giac...@gmail.com"
    wrote:
    > On 28 Gen, 16:32, satish....@gmail.com wrote:
    >
    >
    >
    >
    >
    > > Hi,

    >
    > > I am writing one sample code as below in VxWorks:

    >
    > > void test()
    > > {
    > > * * * printf("\n test..\n");

    >
    > > }

    >
    > > void test_task()
    > > {
    > > * * * *taskSpawn("test", 100, 0, 16*1024, (FUNCPTR)test, 0, 0, 0, 0,
    > > 0, 0, 0, 0, 0, 0);

    >
    > > }

    >
    > > If I am calling "test_task" multiple times in the target shell like
    > > below :

    >
    > > -> sp test_task
    > > task spawned: id = 3d94940, name = s1u0
    > > value = 64571712 = 0x3d94940
    > > ->sp test_task
    > > task spawned: id = 3d9d940, name = s1u1
    > > value = 64571712 = 0x3d94940
    > > ->sp test_task
    > > task spawned: id = 3d9d940, name = s1u2
    > > value = 64571712 = 0x3d94940
    > > ->sp test_task
    > > task spawned: id = 3d9d940, name = s1u3
    > > value = 64571712 = 0x3d94940

    >
    > > By calling this way, will it be multi-tasking?

    >
    > > Please clarify...

    >
    > > Regards
    > > Satish.

    >
    > Sure it will... In your simple example you are calling the "test"
    > function each time in its own context. Your test function returns
    > immediately after the printf, so as soon as you spawn the second task,
    > the first will already be terminated
    >
    > If you modify your test function to be a forever loop, say printing
    > ("This is me %d\n", taskIdSelf()) each second, you will see that the
    > tasks will run concurrently, each of them printing its own Task Id.- Nascondi testo tra virgolette -
    >
    > - Mostra testo tra virgolette -


    btw, as the previous poster said, there is no need to call test_task
    using "sp". In fact, "sp" does quite the same thing than "taskSpawn",
    so you are unnecessarily spawning two task to run the test function.

+ Reply to Thread