예제 #1
0
파일: buffer.c 프로젝트: necto/verifast
void producer(struct buffer *b)
  /*@ requires [_]b->m |-> ?m &*&
               [_]b->v |-> ?v &*&
               [_]b->gid |-> ?gid &*& 
               [_]mutex(m) &*& 
               inv(m) == buffer(b) &*& 
               obs(cons(v,?O)) &*& 
               no_cycle(m,cons(v,O))== true; @*/
  /*@ ensures  [_]b->m |-> m &*& 
               [_]b->v |-> v &*& 
               [_]mutex(m) &*& 
               obs(O); @*/
{
  //@ close mutex_inv(m,buffer(b));
  mutex_acquire(b->m);
  //@ open buffer(b)(?Wt,_);
  //@ close condvar_trn(v,vtrn(gid));
  /*@ if (Wt(v)>0){
        inc_ctr(gid);
        close vtrn(gid)();
      }
  @*/

  condvar_signal(b->v);
  enqueue(b->q,12);
  //@ g_dischl(v);
  //@ assert mutex_held(m,_,?Wt1,?Ot1);
  //@ close buffer(b)(Wt1,Ot1);
  //@ close mutex_inv(m,buffer(b));
  mutex_release(b->m);
}
예제 #2
0
파일: barbershop.c 프로젝트: necto/verifast
void get_haircut1(struct barbershop *b)
  /*@ requires unprotected_permissions(b, ?cbarber, ?cchair, ?cdoor, ?ccustomer, ?gba, ?gch, ?gdo, ?gcu, ?m) &*& [_]mutex(m)
    &*& obs(cons(cchair,cons(ccustomer,?O))) &*& tic(gba) &*& tic(gdo)
    &*& no_cycle(m,cons(cchair,cons(ccustomer,O)))==true 
    &*& no_cycle(cbarber,cons(cchair,cons(ccustomer,O)))==true   
    &*& no_cycle(cdoor,cons(ccustomer,O))==true;
  @*/
  //@ ensures unprotected_permissions(b, cbarber, cchair, cdoor, ccustomer, gba, gch, gdo, gcu, m) &*& [_]mutex(m) &*& obs(O);
{
  //@ open unprotected_permissions(_,_,_,_,_,_,_,_,_,_);
  //@ close mutex_inv(m, barbershop(b));
  mutex_acquire(b->m);
  //@ open barbershop(b)(_,_);
  while (b->barber==0)
    /*@ invariant [_]b->cbarber |-> cbarber &*& [_]b->cchair |-> cchair &*& [_]b->cdoor |-> cdoor &*& [_]b->ccustomer |-> ccustomer
          &*& [_]b->m |-> m &*& b->barber |-> ?barber &*& b->chair |-> ?chair &*& b->door |-> ?door
          &*& barber >= 0 &*& chair >= 0 &*& door >= 0 &*& mutex_held(m, _, ?Wt, ?Ot)
          &*& [_]b->gba |-> gba &*& [_]b->gch |-> gch &*& [_]b->gdo |-> gdo &*& [_]b->gcu |-> gcu
          &*& ctr(gba,?Cba) &*& ctr(gch,?Cch) &*& ctr(gdo,?Cdo) &*& ctr(gcu,?Ccu)
          &*& Wt(cbarber) + Cba <= Ot(cbarber) + barber
          &*& Wt(cbarber) <= Ot(cbarber)
          &*& Wt(cdoor) + Cdo <= Ot(cdoor) + door
          &*& Wt(cdoor) <= Ot(cdoor)
          &*& Wt(cchair) + Cch <= Ot(cchair) + chair
          &*& Wt(cchair) <= Ot(cchair)
          &*& Wt(ccustomer) + Ccu + door <= Ot(ccustomer) + 1
          &*& Wt(ccustomer) <= Ot(ccustomer)     
          &*& obs(cons(m,cons((void*)cchair,cons(ccustomer,O)))) &*& tic(gba) &*& tic(gdo);
    @*/
  {
    //@ dec_ctr(gba);
    //@ close barbershop(b)(finc(Wt,cbarber),Ot);
    //@ close mutex_inv(m,barbershop(b));
    //@ close condvar_trn(cbarber,vtrn(gba));
    condvar_wait(b->cbarber, b->m);
    //@ open barbershop(b)(_,_); 
    //@ open vtrn(gba)();  
  }
  b->barber = b->barber - 1;
  b->chair = b->chair + 1;
  //@ close condvar_trn(cchair,vtrn(gch));
  /*@ if (Wt(cchair)>0){
        inc_ctr(gch);
        close vtrn(gch)();
      }
  @*/
  condvar_signal(b->cchair);
  //@ g_dischl(cchair);
  //@ dec_ctr(gba);
  //@ assert mutex_held(m,_,?Wte,?Ote);
  //@ close barbershop(b)(Wte,Ote);
  //@ close mutex_inv(m, barbershop(b));
  mutex_release(b->m);
  //@ leak [_]mutex(m);
  //@ close unprotected_permissions(b,cbarber,cchair,cdoor,ccustomer,gba,gch,gdo,gcu,m); 
  get_haircut2(b);
  //@ leak [_]mutex(m);
}
예제 #3
0
파일: bitc_ui.c 프로젝트: jma127/bitc-rpc
static void *bitcui_main(void *clientData) {
  sigset_t set;

  sigemptyset(&set);
  sigaddset(&set, SIGQUIT);
  sigaddset(&set, SIGINT);
  pthread_sigmask(SIG_BLOCK, &set, NULL);

  Log(LGPFX " btcui starting.\n");

  bitcui_init();
  condvar_signal(btcui->cv);

  poll_runloop(btcui->poll, &btcui->stop);

  bitcui_exit();
  Log(LGPFX " btcui done.\n");
  pthread_exit(NULL);

  return NULL;
}