Static Mutex Analysis

Would it be wise to have a language that statically validates the mutex? Those.,

var m
var x guarded_by(m)

func f1() {
  lock(m)
  x = 42
  unlock(m)
}

func f2() {
  x = 42  // error, accessing x w/o holding its mutex
}

func f3() assumes_locked(m) {
  x = 42
}

func b1() {
  f3()  // error
}

func b2() {
  lock(m)
  f3()
  unlock(m)
}
  • Is it possible? That is, can a mutex usage fix be statically checked with a few simple annotations like this?
  • It is reasonable? Is there a reason this would be a bad idea?
  • Are there any languages ​​that have this built-in module?
+4
source share
1 answer

Determining the status of a static race

, " " . , , , , :-) ¹ You (1), , (2) (3) . ( , ), :

  • : - ? , /?
  • : - ? , /?
  • : ? , , ..?
  • :. , , ?

, 100% - 1, 2, - ( ). , ² (№ 1 № 3); , , , . ( , , , , , .)

: RaceFreeJava

, (№ 3): , , , , . RaceFreeJava (Abadi et al., 2006). RaceFreeJava - Java, :

  • ( ghost locks);
  • guarded_by, , ;
  • requires, , .

, , , ; , , , , . ghost; ,

class RunningTotals<ghost Object m> {
  private int sum     = 0 guarded_by m;
  private int product = 1 guarded_by m;

  public void include(int x) requires m {
    sum     += x;
    product *= x;
  }

  public int getSum() requires m {
    return sum;
  }

  public int getProduct() requires m {
    return product;
  }
}

RunningTotals - o o lock, ; , , m . , RunningTotals m, m ghost; . , , RaceFreeJava thread_local; , , .

, , , , , Java . RaceFreeJava , ; , , . Abadi et al. . , (, , ) , . - , - Abadi et al. (rccjava) , (Houdini/rcc) . ( I-IV), . , ; Java-, .

, , ( ), , , , RaceFreeJava, , . , .

Boyapati et al. (2002). , , ; , , ; . , accesses locks. Boyapati et al. , . , , . , ( , , ), . , .

, . , , , , , , , ( ), . RacerX (Engler and Ashcraft, 2003) , , Lockset, Eraser (Savage et al., 1997). , , . RacerX , - . Engler Ashcraft RacerX, , ( 5).

, RacerX , , - : , . ; faux-C:

// Thread 1:
acquire(superman_lock);
*superman_bank_account += 100; // Saved Metropolis and got rewarded!
release(superman_lock);

// Thread 2:
acquire(clark_kent_lock);
*clark_kent_bank_account -= 100; // More bills...
release(clark_kent_lock);

, superman_lock clark_kent_lock , , , , superman_bank_account , clark_kent_bank_account. !

Chord (Naik et al., 2006) - , - ; , , , . (, - ), .

. : (1) , (2) (3) ? , ; RaceFreeJava, , , , , . , , . , , , , , , , , , . , , ; , Coverity () , , . , , , .


¹ , , . , , , ! , , ( 2011-2012 ). , - , , , , (, ) ; - ​​, , !

² , Haskell:-) C , Java , , downcasting (* *). .

³ ACM; PDF- , PostScript.


+9

All Articles