You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: lib.rs
    path of file: ./repos/Theseus/kernel/spawn/src
    
    the code of the file until where you have to start completion: //! This crate offers routines for spawning new tasks
//! and convenient builder patterns for customizing new tasks. 
//! 
//! The two functions of interest to create a `TaskBuilder` are:
//! * [`new_task_builder()`][tb]:  creates a new task for a known, existing function.
//! * [`new_application_task_builder()`][atb]: loads a new application crate and creates a new task
//!    for that crate
    
pub fn cleanup_bootstrap_tasks(num_tasks: u32) -> Result<(), &'static str> {
    new_task_builder(
        |total_tasks: u32| {
            let mut num_tasks_cleaned = 0;
            while num_tasks_cleaned < total_tasks {
                if let Some(task) = BOOTSTRAP_TASKS.lock().pop() {
                    match task.join() {
                        Ok(_exit_val) => num_tasks_cleaned += 1,
                        Err(_e) => panic!(
                            "BUG: failed to join bootstrap task {:?}, error: {:?}",
                            task, _e,
                        ),
                    }
                }
            }
            info!("Cleaned up all {} bootstrap tasks.", total_tasks);
            *BOOTSTRAP_TASKS.lock() = Vec::new(); // replace the Vec to drop it
            // SAFETY: Now that all bootstrap tasks are finished executing and have been cleaned up,
            // we can safely deallocate the early TLS data image because it is guaranteed to no
            // longer be in use on any CPU.
            unsafe { early_tls::drop() };
        },
        num_tasks,
    )
    .name(String::from("bootstrap_task_cleanup"))
    .spawn()?;

    Ok(())
}