Best Practices for Cloning A Module


I wrote a compiler and would like to compile a program and clone a module to run programs in parallel from different threads.

I’m able to clone a module easily to achieve this, but I would like to know if there is an efficient way to do it since each thread needs just a separate program data, but can share the same code. Shared code can save a lot of runtime memory.

Could you please share your experience of best practices as a solution for this use case?

Thanks for helping!