代码之家  ›  专栏  ›  技术社区  ›  isekaijin

自旋断言未触发

  •  1
  • isekaijin  · 技术社区  · 6 年前

    ltl { !A@wa U B@sb && !B@wb U A@sa }
    
    byte p = 0
    byte q = 0
    int  x = 0
    
    inline signal(sem) { sem++ }
    inline wait  (sem) { atomic { sem > 0 ; sem-- } }
    
    proctype A() {
        x = 10*x + 1
        signal(p)
    sa: wait(q)
    wa: x = 10*x + 2
    }
    
    proctype B() {
        x = 10*x + 3
        signal(q)
    sb: wait(p)
    wb: x = 10*x + 4
    }
    
    init {
        atomic { run A(); run B() }
        _nr_pr == 1
        assert(x != 1324) 
    }
    

    显然,有一个操作顺序产生最终值 x = 1324 :

    • 最初 x = 0
    • A x = 10*0 + 1 = 1
    • B x = 10*1 + 3 = 13
    • A B
    • A x = 10*13 + 2 = 132
    • x = 10*132 + 4 = 1324
    1 回复  |  直到 6 年前
        1
  •  1
  •   Patrick Trentin    6 年前

    断言没有被触发,因为它是 “从未达到”

    ltl { !A@wa U B@sb && !B@wb U A@sa }
    

    这是真的。

    看看解算器给出的输出,它清楚地表明:

    • Full statespace search for:
          never claim             + (ltl_0)
          assertion violations    + (if within scope of claim)
      
    • 未到达断言:

      unreached in init
          t.pml:27, state 5, "assert((x!=1324))"
          t.pml:28, state 6, "-end-"
          (2 of 6 states)
      

    你可以使用这个选项 -noclaim 因此,只检查断言的模型,然后很容易证明是错误的:

    ~$ spin -search -noclaim t.pml 
    ltl ltl_0: ((! ((A@wa))) U ((B@sb))) && ((! ((B@wb))) U ((A@sa)))
    pan:1: assertion violated (x!=1324) (at depth 13)
    pan: wrote t.pml.trail
    
    (Spin Version 6.4.8 -- 2 March 2018)
    Warning: Search not completed
        + Partial Order Reduction
    
    Full statespace search for:
        never claim             - (not selected)
        assertion violations    +
        cycle checks        - (disabled by -DSAFETY)
        invalid end states  +
    
    State-vector 36 byte, depth reached 15, errors: 1
           48 states, stored
            6 states, matched
           54 transitions (= stored+matched)
            1 atomic steps
    hash conflicts:         0 (resolved)
    
    Stats on memory usage (in Megabytes):
        0.003   equivalent memory usage for states (stored*(State-vector + overhead))
        0.286   actual memory usage for states
      128.000   memory used for hash table (-w24)
        0.534   memory used for DFS stack (-m10000)
      128.730   total actual memory usage
    
    
    
    pan: elapsed time 0 seconds