locked
how to model two parallel actions RRS feed

  • Question

  • Hi,

    we need to create a model to illustrate doing A and doing B at same time. They start from the same initial state, and can happen in parallel. And they stop at the same ending state. In the following figure, A->B and A->C can happen at the same time. When they go to the end state D, they will have both value from B and C.

    How should we do this?

    Saturday, November 26, 2011 9:11 PM

All replies

  • Hi, xyzBecca,

    First I want to know your requirement of this parallel modeling. You said they can happen at the same time, does that mean they should always happen at the same time? If you do not care who occurs first, a typical way can be what your graph shows: there is no constraint about who occurs first, but one action can only occur once. For example, you can write the code like this:


    static bool NotExecutedA=true;
    static bool NotExecutedB=true;

    [Rule]
    static void A()
    {
     Condition.IsTrue(NotExecutedA);
     NotExecutedA=false;
    }

    [Rule]
    static void A()
    {
     Condition.IsTrue(NotExecutedB);
     NotExecutedB=false;
    }

    If at test runtime, they really need to happen in parallel, you can also abstract A and B to one action (e.g. ExecuteAandB), and let adapters to handle parallel invoking.

    Let me know if it works.

    Thanks,

    Xiang

    Monday, November 28, 2011 6:08 AM
    Moderator
  • Hi Xiang,

    Thanks for your reply. The solution works for me. Also, I have two more questions about "action".

    1. for example, I claim an action like following

    action abstract SUI.User()

    User() is a constructor in the model. I don't have implementation to be bound. When I compile, it has error saying "abstract method can not be constructor". The question is how to claim a constructor if we don't bind the model to implementation.

    2. If I want to declare  an action as below

    action abstract User FindUser(string name);

    How to make the cord recognized the data type User which is a class defined in the model.cs. Again, this is built under the condition without binding implementation or adapters.

     

    Thanks

    Rebecca

    Monday, November 28, 2011 5:45 PM
  • Hi, xyzBecca,

    First I want to know your requirement of this parallel modeling. You said they can happen at the same time, does that mean they should always happen at the same time? If you do not care who occurs first, a typical way can be what your graph shows: there is no constraint about who occurs first, but one action can only occur once. For example, you can write the code like this:


    static bool NotExecutedA=true;
    static bool NotExecutedB=true;

    [Rule]
    static void A()
    {
     Condition.IsTrue(NotExecutedA);
     NotExecutedA=false;
    }

    [Rule]
    static void A()
    {
     Condition.IsTrue(NotExecutedB);
     NotExecutedB=false;
    }

    If at test runtime, they really need to happen in parallel, you can also abstract A and B to one action (e.g. ExecuteAandB), and let adapters to handle parallel invoking.

    Let me know if it works.

    Thanks,

    Xiang

    Hi Xiang,

    Can you elaborate more on how to make A and B execute in parallel (true concurrency, not interleaving mode) using adapters ?

    Thanks,

    Jamel.

    Monday, December 19, 2011 5:51 PM
  • Hi Rebecca,

    For your first question, Spec Explorer does not allow abstract constructor, that is by-design. Can you tell me more information about why you need abstract constructor? The root cause is that we cannot fake an instance of a type.

    For the second question, if you use abstract, Spec Explorer will not solve the type by default. So you can remove abstract keyword and use the corresponding namespace (the namespace containing the type) in cord. Cord will not import modeling namespace by default.

    Saturday, January 7, 2012 2:21 PM
    Moderator
  • Hi Jamel,

    My idea is to wrap the parallel execution in adapter. So there is just one rule, and when the corresponding action is invoked, you can develop multi-thread code in the action to make things parallel.

    Jameil, I saw another thread focusing on parallel state update, if that is what you want, then test adapter cannot help. Test adapter only works when you want to execute "implementation" methods in parallel, not modeling rules.

    Thanks,

    Xiang

    Saturday, January 7, 2012 2:26 PM
    Moderator