From ce6abf77501fb5976653d31203e8a7c423c05a62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Fri, 2 Jan 2026 18:57:39 +0100 Subject: [PATCH] Even more traces, identifying parent, child and grandchild --- test/robust_mutex_test.hpp | 43 ++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/test/robust_mutex_test.hpp b/test/robust_mutex_test.hpp index d270c62..db01f3e 100644 --- a/test/robust_mutex_test.hpp +++ b/test/robust_mutex_test.hpp @@ -35,7 +35,7 @@ int robust_mutex_test(int argc, char *argv[]) // test_all_lock(); // test_all_mutex(); } - std::cout << "robust mutex recovery test" << std::endl; + std::cout << "PARENT: robust mutex recovery test" << std::endl; //Remove shared memory on construction and destruction class shm_remove @@ -62,20 +62,22 @@ int robust_mutex_test(int argc, char *argv[]) //Launch child process std::string s(argv[0]); s += " child "; s += get_process_id_name(); - std::cout << "... launching child: " << s << std::endl; + std::cout << "PARENT: ... launching child: " << s << std::endl; int r = std::system(s.c_str()); if(0 != r){ - std::cout << "From PARENT --> std::system" << s.c_str() << " FAILED with " << r << std::endl; + std::cout << "PARENT: std::system" << s.c_str() << " FAILED with " << r << std::endl; return 1; } + std::cout << "PARENT: ... launched child: " << s << std::endl; + //Wait until child locks the mutexes and dies spin_wait swait; while(!*go_ahead){ swait.yield(); } - std::cout << "... recovering mutex[0]" << std::endl; + std::cout << "PARENT: ... recovering mutex[0]" << std::endl; //First try to recover lock[0], put into consistent //state and relock it again { @@ -83,7 +85,7 @@ int robust_mutex_test(int argc, char *argv[]) //mutex recovery works instance[0].lock(); if(!instance[0].previous_owner_dead()){ - std::cout << "instance[0].previous_owner_dead() FAILED!" << std::endl; + std::cout << "PARENT: instance[0].previous_owner_dead() FAILED!" << std::endl; return 1; } instance[0].consistent(); @@ -94,13 +96,13 @@ int robust_mutex_test(int argc, char *argv[]) } //Now with lock[1], but dont' put it in consistent state //so the mutex is no longer usable - std::cout << "... recovering mutex[1]" << std::endl; + std::cout << "PARENT: ... recovering mutex[1]" << std::endl; { //Done, now try to lock it to see if robust //mutex recovery works instance[1].lock(); if(!instance[1].previous_owner_dead()){ - std::cout << "instance[1].previous_owner_dead() FAILED!" << std::endl; + std::cout << "PARENT: instance[1].previous_owner_dead() FAILED!" << std::endl; return 1; } //Unlock a recovered mutex without putting it into @@ -115,19 +117,19 @@ int robust_mutex_test(int argc, char *argv[]) exception_thrown = true; } BOOST_INTERPROCESS_CATCH_END if(!exception_thrown){ - std::cout << "instance[1].lock() did NOT throw an exception!" << std::endl; + std::cout << "PARENT: instance[1].lock() did NOT throw an exception!" << std::endl; return 1; } } //Now with lock[2], this was locked by child but not //unlocked - std::cout << "... recovering mutex[2]" << std::endl; + std::cout << "PARENT: ... recovering mutex[2]" << std::endl; { //Done, now try to lock it to see if robust //mutex recovery works instance[2].lock(); if(!instance[2].previous_owner_dead()){ - std::cout << "instance[2].previous_owner_dead() FAILED" << std::endl; + std::cout << "PARENT: instance[2].previous_owner_dead() FAILED" << std::endl; return 1; } //Unlock a recovered mutex without putting it into @@ -142,7 +144,7 @@ int robust_mutex_test(int argc, char *argv[]) exception_thrown = true; } BOOST_INTERPROCESS_CATCH_END if(!exception_thrown){ - std::cout << "instance[2].lock() did not throw an Exception!" << std::endl; + std::cout << "PARENT: instance[2].lock() did not throw an Exception!" << std::endl; return 1; } } @@ -154,7 +156,7 @@ int robust_mutex_test(int argc, char *argv[]) RobustMutex *instance = segment.find("robust mutex").first; assert(instance); if(std::string(argv[1]) == std::string("child")){ - std::cout << "Launched child" << std::endl; + std::cout << "CHILD: starting" << std::endl; //Find flag bool *go_ahead = segment.find("go ahead").first; assert(go_ahead); @@ -162,7 +164,7 @@ int robust_mutex_test(int argc, char *argv[]) bool try_lock_res = instance[0].try_lock() && instance[1].try_lock(); assert(try_lock_res); if(!try_lock_res){ - std::cout << "'instance[0].try_lock() && instance[1].try_lock()' FAILED!" << std::endl; + std::cout << "CHILD: 'instance[0].try_lock() && instance[1].try_lock()' FAILED!" << std::endl; return 1; } @@ -171,12 +173,13 @@ int robust_mutex_test(int argc, char *argv[]) //Launch grandchild std::string s(argv[0]); s += " grandchild "; s += argv[2]; - std::cout << "... launching grandchild: " << s << std::endl; + std::cout << "CHILD: launching grandchild: " << s << std::endl; int r = std::system(s.c_str()); if(0 != r){ - std::cout << "From CHILD --> std::system" << s.c_str() << " FAILED with " << r << std::endl; + std::cout << "CHILD: --> std::system" << s.c_str() << " FAILED with " << r << std::endl; return 1; } + std::cout << "CHILD: Launched grandchild: " << s << std::endl; //Wait until child locks the 2nd mutex and dies spin_wait swait; @@ -188,14 +191,14 @@ int robust_mutex_test(int argc, char *argv[]) //mutex recovery works instance[2].lock(); if(!instance[2].previous_owner_dead()){ - std::cout << "instance[2].previous_owner_dead() FAILED!" << std::endl; + std::cout << "CHILD: instance[2].previous_owner_dead() FAILED!" << std::endl; return 1; } *go_ahead = true; - std::cout << "Exiting child" << std::endl; + std::cout << "CHILD: Exiting" << std::endl; } else{ - std::cout << "Launched grandchild" << std::endl; + std::cout << "GRANDCHILD: Starting" << std::endl; //grandchild locks the lock and dies bool *go_ahead2 = segment.find("go ahead2").first; assert(go_ahead2); @@ -203,11 +206,11 @@ int robust_mutex_test(int argc, char *argv[]) bool try_lock_res = instance[2].try_lock(); assert(try_lock_res); if(!try_lock_res){ - std::cout << "instance[2].try_lock() FAILED!" << std::endl; + std::cout << "GRANDCHILD: instance[2].try_lock() FAILED!" << std::endl; return 1; } *go_ahead2 = true; - std::cout << "Exiting grandchild" << std::endl; + std::cout << "GRANDCHILD: Exiting" << std::endl; } } }BOOST_INTERPROCESS_CATCH(...){