@@ -35,7 +35,7 @@ int robust_mutex_test(int argc, char *argv[])
3535 // test_all_lock<RobustMutex>();
3636// test_all_mutex<true, RobustMutex>();
3737 }
38- std::cout << " robust mutex recovery test" << std::endl;
38+ std::cout << " PARENT: robust mutex recovery test" << std::endl;
3939
4040 // Remove shared memory on construction and destruction
4141 class shm_remove
@@ -62,28 +62,30 @@ int robust_mutex_test(int argc, char *argv[])
6262 // Launch child process
6363 std::string s (argv[0 ]); s += " child " ;
6464 s += get_process_id_name ();
65- std::cout << " ... launching child: " << s << std::endl;
65+ std::cout << " PARENT: ... launching child: " << s << std::endl;
6666 int r = std::system (s.c_str ());
6767 if (0 != r){
68- std::cout << " From PARENT --> std::system" << s.c_str () << " FAILED with " << r << std::endl;
68+ std::cout << " PARENT: std::system" << s.c_str () << " FAILED with " << r << std::endl;
6969 return 1 ;
7070 }
7171
72+ std::cout << " PARENT: ... launched child: " << s << std::endl;
73+
7274 // Wait until child locks the mutexes and dies
7375 spin_wait swait;
7476 while (!*go_ahead){
7577 swait.yield ();
7678 }
7779
78- std::cout << " ... recovering mutex[0]" << std::endl;
80+ std::cout << " PARENT: ... recovering mutex[0]" << std::endl;
7981 // First try to recover lock[0], put into consistent
8082 // state and relock it again
8183 {
8284 // Done, now try to lock it to see if robust
8385 // mutex recovery works
8486 instance[0 ].lock ();
8587 if (!instance[0 ].previous_owner_dead ()){
86- std::cout << " instance[0].previous_owner_dead() FAILED!" << std::endl;
88+ std::cout << " PARENT: instance[0].previous_owner_dead() FAILED!" << std::endl;
8789 return 1 ;
8890 }
8991 instance[0 ].consistent ();
@@ -94,13 +96,13 @@ int robust_mutex_test(int argc, char *argv[])
9496 }
9597 // Now with lock[1], but dont' put it in consistent state
9698 // so the mutex is no longer usable
97- std::cout << " ... recovering mutex[1]" << std::endl;
99+ std::cout << " PARENT: ... recovering mutex[1]" << std::endl;
98100 {
99101 // Done, now try to lock it to see if robust
100102 // mutex recovery works
101103 instance[1 ].lock ();
102104 if (!instance[1 ].previous_owner_dead ()){
103- std::cout << " instance[1].previous_owner_dead() FAILED!" << std::endl;
105+ std::cout << " PARENT: instance[1].previous_owner_dead() FAILED!" << std::endl;
104106 return 1 ;
105107 }
106108 // Unlock a recovered mutex without putting it into
@@ -115,19 +117,19 @@ int robust_mutex_test(int argc, char *argv[])
115117 exception_thrown = true ;
116118 } BOOST_INTERPROCESS_CATCH_END
117119 if (!exception_thrown){
118- std::cout << " instance[1].lock() did NOT throw an exception!" << std::endl;
120+ std::cout << " PARENT: instance[1].lock() did NOT throw an exception!" << std::endl;
119121 return 1 ;
120122 }
121123 }
122124 // Now with lock[2], this was locked by child but not
123125 // unlocked
124- std::cout << " ... recovering mutex[2]" << std::endl;
126+ std::cout << " PARENT: ... recovering mutex[2]" << std::endl;
125127 {
126128 // Done, now try to lock it to see if robust
127129 // mutex recovery works
128130 instance[2 ].lock ();
129131 if (!instance[2 ].previous_owner_dead ()){
130- std::cout << " instance[2].previous_owner_dead() FAILED" << std::endl;
132+ std::cout << " PARENT: instance[2].previous_owner_dead() FAILED" << std::endl;
131133 return 1 ;
132134 }
133135 // Unlock a recovered mutex without putting it into
@@ -142,7 +144,7 @@ int robust_mutex_test(int argc, char *argv[])
142144 exception_thrown = true ;
143145 } BOOST_INTERPROCESS_CATCH_END
144146 if (!exception_thrown){
145- std::cout << " instance[2].lock() did not throw an Exception!" << std::endl;
147+ std::cout << " PARENT: instance[2].lock() did not throw an Exception!" << std::endl;
146148 return 1 ;
147149 }
148150 }
@@ -154,15 +156,15 @@ int robust_mutex_test(int argc, char *argv[])
154156 RobustMutex *instance = segment.find <RobustMutex>(" robust mutex" ).first ;
155157 assert (instance);
156158 if (std::string (argv[1 ]) == std::string (" child" )){
157- std::cout << " Launched child " << std::endl;
159+ std::cout << " CHILD: starting " << std::endl;
158160 // Find flag
159161 bool *go_ahead = segment.find <bool >(" go ahead" ).first ;
160162 assert (go_ahead);
161163 // Lock, flag and die
162164 bool try_lock_res = instance[0 ].try_lock () && instance[1 ].try_lock ();
163165 assert (try_lock_res);
164166 if (!try_lock_res){
165- std::cout << " 'instance[0].try_lock() && instance[1].try_lock()' FAILED!" << std::endl;
167+ std::cout << " CHILD: 'instance[0].try_lock() && instance[1].try_lock()' FAILED!" << std::endl;
166168 return 1 ;
167169 }
168170
@@ -171,12 +173,13 @@ int robust_mutex_test(int argc, char *argv[])
171173 // Launch grandchild
172174 std::string s (argv[0 ]); s += " grandchild " ;
173175 s += argv[2 ];
174- std::cout << " ... launching grandchild: " << s << std::endl;
176+ std::cout << " CHILD: launching grandchild: " << s << std::endl;
175177 int r = std::system (s.c_str ());
176178 if (0 != r){
177- std::cout << " From CHILD --> std::system" << s.c_str () << " FAILED with " << r << std::endl;
179+ std::cout << " CHILD: --> std::system" << s.c_str () << " FAILED with " << r << std::endl;
178180 return 1 ;
179181 }
182+ std::cout << " CHILD: Launched grandchild: " << s << std::endl;
180183
181184 // Wait until child locks the 2nd mutex and dies
182185 spin_wait swait;
@@ -188,26 +191,26 @@ int robust_mutex_test(int argc, char *argv[])
188191 // mutex recovery works
189192 instance[2 ].lock ();
190193 if (!instance[2 ].previous_owner_dead ()){
191- std::cout << " instance[2].previous_owner_dead() FAILED!" << std::endl;
194+ std::cout << " CHILD: instance[2].previous_owner_dead() FAILED!" << std::endl;
192195 return 1 ;
193196 }
194197 *go_ahead = true ;
195- std::cout << " Exiting child " << std::endl;
198+ std::cout << " CHILD: Exiting " << std::endl;
196199 }
197200 else {
198- std::cout << " Launched grandchild " << std::endl;
201+ std::cout << " GRANDCHILD: Starting " << std::endl;
199202 // grandchild locks the lock and dies
200203 bool *go_ahead2 = segment.find <bool >(" go ahead2" ).first ;
201204 assert (go_ahead2);
202205 // Lock, flag and die
203206 bool try_lock_res = instance[2 ].try_lock ();
204207 assert (try_lock_res);
205208 if (!try_lock_res){
206- std::cout << " instance[2].try_lock() FAILED!" << std::endl;
209+ std::cout << " GRANDCHILD: instance[2].try_lock() FAILED!" << std::endl;
207210 return 1 ;
208211 }
209212 *go_ahead2 = true ;
210- std::cout << " Exiting grandchild " << std::endl;
213+ std::cout << " GRANDCHILD: Exiting " << std::endl;
211214 }
212215 }
213216 }BOOST_INTERPROCESS_CATCH (...){
0 commit comments