
use core

fn thread_init(is_main: bool (false)) {
    //
    core:error_trace_index = 0
    core:error_trace[0] = "-no-error-"

    pools_init()
    gc = Gc.init()
    //
    if is_main {
        mark = 2
        mem_shared_trigger = mem_minimum_trigger
        running_shared = false

        #if TEST
        verify = true
        #else
        verify = false
        #end

        //
        shared_lock = core:MutexStruct[void].new()
        gc_list = Array[Gc].new()
    }
    // Add to gc list
    gc.lock()
    shared_lock.lock()
    gc_list.append(gc)
    shared_lock.unlock()
}

fn thread_stop() {
    //
    gc.unlock()
    // Remove from gc list
    shared_lock.lock()
    gc_list.remove_value(gc)
    shared_lock.unlock()
    //
    gc.shutdown()
    // Free pools
    pools_free()
}
