All pastes #449199 Raw Edit

Untitled

public c v1 · immutable
·published 2007-04-20 02:37 UTC
rendered paste body
const int K = 11;int n;semaphore counter;int i;void A (){        if (n == 0) {                wait(counter);        } else {                n--;        }        cout << "\nA RUNS AND N IS " << n << "\n";}void B (){        signal(counter);        n++;        cout << "\nB RUNS AND N IS " << n << "\n";}main(){        n = 0;        initialsem(counter,0);        cobegin        {                for (i = 0; i<K; i++)                {                        A(); B();                }        }        cout << "The sum is " << n << endl;}