From ed86b48cc9a8349e8e99de5f013f68f1edff4121 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 25 Nov 2013 18:27:27 -0800 Subject: Clean up statically initialized data on shutdown Whenever the runtime is shut down, add a few hooks to clean up some of the statically initialized data of the runtime. Note that this is an unsafe operation because there's no guarantee on behalf of the runtime that there's no other code running which is using the runtime. This helps turn down the noise a bit in the valgrind output related to statically initialized mutexes. It doesn't turn the noise down to 0 because there are still statically initialized mutexes in dynamic_lib and os::with_env_lock, but I believe that it would be easy enough to add exceptions for those cases and I don't think that it's the runtime's job to go and clean up that data. --- src/libstd/rt/mod.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/libstd/rt/mod.rs') diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 860b65b20c6..79b7dbf2aab 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -215,7 +215,8 @@ pub fn start(argc: int, argv: **u8, main: proc()) -> int { init(argc, argv); let exit_code = run(main); - cleanup(); + // unsafe is ok b/c we're sure that the runtime is gone + unsafe { cleanup(); } return exit_code; } @@ -228,7 +229,8 @@ pub fn start(argc: int, argv: **u8, main: proc()) -> int { pub fn start_on_main_thread(argc: int, argv: **u8, main: proc()) -> int { init(argc, argv); let exit_code = run_on_main_thread(main); - cleanup(); + // unsafe is ok b/c we're sure that the runtime is gone + unsafe { cleanup(); } return exit_code; } @@ -249,8 +251,17 @@ pub fn init(argc: int, argv: **u8) { } /// One-time runtime cleanup. -pub fn cleanup() { +/// +/// This function is unsafe because it performs no checks to ensure that the +/// runtime has completely ceased running. It is the responsibility of the +/// caller to ensure that the runtime is entirely shut down and nothing will be +/// poking around at the internal components. +/// +/// Invoking cleanup while portions of the runtime are still in use may cause +/// undefined behavior. +pub unsafe fn cleanup() { args::cleanup(); + local_ptr::cleanup(); } /// Execute the main function in a scheduler. -- cgit 1.4.1-3-g733a5