#19 tasks calling functions

compiler
closed-works-for-me
John Hansen
NXC (53)
5
2007-07-17
2007-07-13
sfawzy
No

can i have a 2 tasks call the same function at the same time!!

Discussion

  • John Hansen
    John Hansen
    2007-07-13

    Logged In: YES
    user_id=661666
    Originator: NO

    Only if you upgrade to b31 and mark your function as inline or safecall. Your best bet is to mark the function as inline since that will allow both tasks to execute the code in your inline function simultaneously. If you mark your function as safecall then one of the two tasks will execute the function first and the other will have to wait until the function returns to the first task. In many situations this behavior is fine.

    If you use shared resources such as motors or sensor ports within your function then you will not get simultaneous execution.

    Use this syntax with the new NXC beta release (b31):

    inline int MyFunc(int x, int y)
    {
    return x*y;
    }

    task one()
    {
    int value = MyFunc(2, 5);
    while(true);
    }

    task two()
    {
    int value2 = MyFunc(12, 5);
    while(true);
    }

    task main()
    {
    Precedes(one, two);
    }

     
  • John Hansen
    John Hansen
    2007-07-17

    • status: open --> closed-works-for-me