using Base.Threads println("Active Julia threads: ", nthreads()) # A CPU-heavy helper function function compute_work(id, iterations) println(" [Start] Task $id on Thread #", threadid()) total = 0.0 for i in 1:iterations total += sin(i) * cos(i) end println(" [Done] Task $id on Thread #", threadid()) return total end # ==================================================================== # 1. Basic @spawn and fetch # ==================================================================== println("\n--- 1. Single Task Spawning ---") # Threads.@spawn creates a Task and schedules it onto an available worker thread task1 = Threads.@spawn compute_work("A", 10_000_000) println(typeof(task1))