11 IntWrapper(int val) : _val(val) {}
13 IntWrapper() : _val(0) {}
15 IntWrapper(IntWrapper& copy) : _val(copy._val) {}
22 static void* read_int(void *int_wrapper) {
23 IntWrapper *ptr = (IntWrapper*) int_wrapper;
24 return (void*) new int(ptr->get());
28 static IntWrapper *shared_int = new IntWrapper(10);
29 static seqlock<IntWrapper> my_lock(shared_int);
31 static void read_thrd(void *obj) {
32 void *res = my_lock.read(read_int);
33 cout << "Thread read: " << *((int*) res) << endl;
36 static void write_thrd(void *obj) {
37 IntWrapper *new_int = new IntWrapper(1024);
38 my_lock.write(new_int);
39 cout << "Thread write: " << new_int->get() << endl;
42 int main(int argc, char *argv[]) {
45 thrd_create(&t1, (thrd_start_t) &read_thrd, NULL);
46 thrd_create(&t2, (thrd_start_t) &write_thrd, NULL);
47 thrd_create(&t3, (thrd_start_t) &read_thrd, NULL);