Ticket #10128: example_lock_constObject.cpp

File example_lock_constObject.cpp, 821 bytes (added by anonymous, 8 years ago)

Error example

Line 
1// example_lock_constObject.cpp: define el punto de entrada de la aplicación de consola.
2//
3
4#include "stdafx.h"
5#include <boost\thread\recursive_mutex.hpp>
6#include <boost/thread/lockable_adapter.hpp>
7#include <boost/thread/locks.hpp>
8
9class Class1 :
10 public boost::lockable_adapter<boost::recursive_mutex>
11{
12public:
13 Class1() :_i(0){}
14 virtual ~Class1(){}
15
16 void set(int i) {
17 _i = i;
18 }
19
20 int get() const {
21 return _i;
22 }
23
24private:
25 int _i;
26};
27
28int func(const Class1& obj)
29{
30 boost::unique_lock<Class1> lock(obj);
31 //boost::unique_lock<Class1> lock(const_cast<Class1&>(obj));
32 return obj.get();
33}
34
35
36int _tmain(int argc, _TCHAR* argv[])
37{
38 Class1 obj;
39 boost::unique_lock<Class1> lock(obj);
40 obj.set(1);
41
42 return 0;
43}
44