#include <boost/thread.hpp>
#include <iostream>

int ei_teller(0);
boost::mutex m;
boost::condition_variable c;

void thread1() {
	while (1) {
		boost::unique_lock<boost::mutex> lock(m);
		while (ei_teller<12)
			c.wait(lock);
		ei_teller-=12;
		std::cout<<"Ei_teller is verlaagd en is nu "<<ei_teller<<std::endl;
	}
}

void thread2() {
	int n=0;
	std::cout<<"Geef waarden voor n (negatief om te stoppen): ";
	while (n>=0) {
		std::cin>>n;
		if (n>=0) {
			boost::lock_guard<boost::mutex> lock(m);
			ei_teller+=n;
			c.notify_one();
		}
	}
}

int main() { 
	boost::thread t1(&thread1); 
	boost::thread t2(&thread2); 
	t2.join();
	std::cout<<"Einde."<<std::endl;
	std::cin.get();	std::cin.get();
	return 0; 
}
