Exemple #1
0
void TicketLock__main(){
	PREDICATE(c == 0);
	PREDICATE(c == 1);
	while(1){
		acquire_lock();
		c++;assert(c == 1);c--;
		release_lock();
	}
}
Exemple #2
0
void acquire_lock(){
	unsigned my_ticket = fetch_and_increment__next_ticket(); 
	PREDICATE(my_ticket == 0);
	PREDICATE(my_ticket == 1);
	PREDICATE(my_ticket == 2);
	//PREDICATE(my_ticket == 3);
	PREDICATE(lock.now_serving == my_ticket);
	//returns old value; arithmetic overflow is harmless
	while(1){
#ifndef SIMPL
		pause(my_ticket - lock.now_serving);
#endif
		// consume this many units of time
		// on most machines, subtraction works correctly despite overflow
		if(lock.now_serving == my_ticket)
			return;
	}
}
Exemple #3
0
atom_t
brz_deriv( atom_t atom, int c )
{
   if( characterp(atom) )
      return PREDICATE( equalp(atom, ULISP_CHAR(c)) );

   if( re_is_seq(atom) )
      return re_alt(
         re_seq( brz_deriv(cadr(atom), c), caddr(atom) ),
         re_seq( PREDICATE(brz_is_nullable(cadr(atom))), brz_deriv(caddr(atom), c) ));

   if( re_is_alt(atom) )
      return re_alt( brz_deriv(cadr(atom), c), brz_deriv(caddr(atom), c) );

   if( re_is_rep(atom) )
      return re_seq( brz_deriv(cadr(atom), c), re_rep(cadr(atom)) );

   return PREDICATE( re_is_any(atom) );
}
Exemple #4
0
unsigned fetch_and_increment__next_ticket(){
	unsigned value;
	PRETPREDS
	PREDICATE(value == lock.next_ticket);
	PREDICATE(value == 0);
	PREDICATE(value == 1);
	PREDICATE(value == 2);
	//PREDICATE(value == 3);
	atomic_begin();
		value = lock.next_ticket;
#ifdef SIMPL
		//Alex: now sure whether this is allowed
		lock.next_ticket =  (lock.next_ticket + 1)%3;
#else
		lock.next_ticket++;
#endif
	atomic_end();
    return value;
}
Exemple #5
0
int main(){
	PREDICATE(lock.now_serving == 0);
	PREDICATE(lock.now_serving == 1);
	PREDICATE(lock.now_serving == 2);
	//PREDICATE(lock.now_serving == 3);
	PREDICATE(lock.next_ticket == 0);
	PREDICATE(lock.next_ticket == 1);
	PREDICATE(lock.next_ticket == 2);
	//PREDICATE(lock.next_ticket == 3);
	while(1) __CPROVER_ASYNC_1: TicketLock__main();
}