Closed as not planned
Description
Bug report
Bug description:
Windows 11, WSL Archlinux
Hash 1b1db2f
Linux Jeferson 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 GNU/Linux
My test file
import threading
import time
# Shared resource
shared_resource = 0
# Lock for synchronization
# lock = threading.Lock()
# Define a function that will be executed by each thread
def worker():
global shared_resource
for n in range(1000000): # Perform some computation
# with lock:
shared_resource += n
def run_threads(num_threads):
start_time = time.time()
# Create a list to store references to the threads
threads = []
# Create and start the specified number of threads
for _ in range(num_threads):
thread = threading.Thread(target=worker)
thread.start()
threads.append(thread)
# Wait for all threads to complete
for thread in threads:
thread.join()
end_time = time.time()
elapsed_time = end_time - start_time
print(f"Ran {num_threads} threads cooperatively in {elapsed_time:.2f} seconds")
# Run the benchmark with different numbers of threads
for num_threads in [1, 2, 4, 8, 20]:
run_threads(num_threads)
jefer@Jeferson ~/d/w/a/b/threads (development)> PYTHON_GIL=1 /opt/python-beta/bin/python3 -Xgil=1 -m main
Ran 1 threads cooperatively in 0.04 seconds
Ran 2 threads cooperatively in 0.09 seconds
Ran 4 threads cooperatively in 0.18 seconds
Ran 8 threads cooperatively in 0.35 seconds
Ran 20 threads cooperatively in 0.86 seconds
jefer@Jeferson ~/d/w/a/b/threads (development)> PYTHON_GIL=0 /opt/python-beta/bin/python3 -Xgil=0 -m main
Ran 1 threads cooperatively in 0.04 seconds
Ran 2 threads cooperatively in 0.10 seconds
Ran 4 threads cooperatively in 0.35 seconds
Ran 8 threads cooperatively in 1.50 seconds
Ran 20 threads cooperatively in 22.48 seconds
I think that GIL 0 means no GIL, but it's slower.
CPython versions tested on:
3.13, CPython main branch
Operating systems tested on:
Linux, Other