示例工程 19-threading-gil-multiprocessing
19-threading-gil-multiprocessing/01-cpu-bound-threads/README.md
# 01 · cpu-bound-threads
**演示**:4 个 CPU 密集任务,串行与 4 线程耗时几乎相同(甚至更慢);GIL 让同一进程内的 Python 字节码不能并行执行。
**运行**:
```sh
uv run python examples/19-threading-gil-multiprocessing/01-cpu-bound-threads/cpu_bound_threads.py
```
**预期输出**(3.12.9,耗时随机器波动):
```text
serial: 499999500000 0.06s
threaded: 499999500000 0.06s
speedup: 0.98x
```
**依赖**:仅标准库。
**注意**:多线程仍适合 IO 等待(见 02);CPU 密集要用多进程(04)或 C 扩展释放 GIL。