Basically, a window must be deactivated (SetActive(false)) in the thread where it is active, before being used in another thread.
But you don't need a thread at all for what you do. Your thread spends most of its time doing nothing, and worst, the main thread is waiting until the other thread is finished (you could call prepare_function directly, it would have the exact same effect). So it's absolutely useless
A thread for audio is not necessary, sounds are already played in a separate thread so that the main thread is never blocked.
A thread for drawing... I'd say it's useless too, unless you have already thought about it and have really good arguments for it.
Threading is not magical, it must be used carefully and it involves a lot of new concepts and problems.