Ejemplo n.º 1
0
int name(int &mySum, Futex& f)
{
    while (true) {
        f.lock();
        if (ans >= MAX_ANS){
            f.unlock();
            break;
        }
        ++ans;
        ++mySum;
        f.unlock();
    }
    return 0;
}
Ejemplo n.º 2
0
void worker(int threadId,
            int targ_max,
            int &target,
            vector<int> &incrementsCounter,
            Futex &futex) {
    while(true) {
        futex.lock(threadId);
        if (target < targ_max) {
            target++;
            incrementsCounter[threadId]++;
            futex.unlock(threadId);
        } else {
            futex.unlock(threadId);
            break;
        }
    }
}