#include <thread>
#include <mutex>
#include <iostream>
using namespace std;

class Point {
public:
    Point(): x(0), y(0) {
    }
    void stepNorthEast() {
        m.lock();
        x++;
        y++;
        m.unlock();
    }
    bool isNorthEast() const {
        m.lock();
        bool res = x == y;
        m.unlock();
        return res;
    }
    bool isWithinLimits() const {
        m.lock();
        bool res = x >= 0 && x <= 1000000 && y >= 0 && y <= 1000000;
        m.unlock();
        return res;
    }
private:
    mutable mutex m;
    int x, y;
};

class TestPoint {
private:
    Point p;
    void thread1() {
        for (int i = 0; i < 2000000; i++)
            p.stepNorthEast();
    }
    void thread2() {
        for (int i = 0; i < 2000000; i++)
            if (!p.isNorthEast())
                cout << "Probleem!" << endl;
    }
    void thread3() {
        for (int i = 0; i < 2000000; i++)
            if (!p.isWithinLimits()) {
                cout << "Buiten grenzen!" << endl;
                return;
            }
    }
public:
    void test() {
        thread t1(&TestPoint::thread1, this); 
        thread t2(&TestPoint::thread2, this); 
        thread t3(&TestPoint::thread3, this); 
        t1.join();
        t2.join();
        t3.join();
        cout << "Einde." << endl;
    }
};

int main() { 
    TestPoint tp;
    tp.test();
    cin.get();
    return 0; 
}