Exemplo n.º 1
0
void reader(rw_data &d){
	int x;
	for(int i=0;i < 10; ++i){
		this_thread::sleep(posix_time::milliseconds(5));
		d.read(&x);
		mutex::scoped_lock lock(io_mu);
		cout <<"#" << this_thread::get_id() << ", reader:" << x << endl;
	}
}
Exemplo n.º 2
0
void writer(rw_data& d)
{
	using namespace boost;
	for(int i = 0; i < 20; i++)
	{
		this_thread::sleep(posix_time::millisec(10));
		d.write();
	}
}
Exemplo n.º 3
0
void reader(rw_data& d)
{
	using namespace boost;
	int x;
	for(int i = 0; i < 10; i++)
	{
		this_thread::sleep(posix_time::millisec(5));
		d.read(&x);
		mutex::scoped_lock lock(io_mutex);
		cout << "reader: " << x << endl;
	}
}
Exemplo n.º 4
0
void writer(rw_data &d){
	for(int i=0;i < 20; ++i){
		this_thread::sleep(posix_time::milliseconds(10));
		d.write();
	}
}