Code
python
import threading
from concurrent.futures import ThreadPoolExecutor
def task(n):
return n * n
# Using thread pool
with ThreadPoolExecutor(max_workers=4) as pool:
results = list(pool.map(task, range(10)))
print(results)
# Manually create thread
threads = []
for i in range(5):
t = threading.Thread(target=task, args=(i,))
threads.append(t)
t.start()
for t in threads:
t.join()