ProgrammingHardGATE CS · Product-company placement

In CPython, two threads each run a pure-Python CPU-bound loop (no I/O, no C extensions releasing the lock) on a 4-core machine. Compared with running the two loops one after the other in a single thread, the total wall-clock time with threads is typically:

  1. A. About half, because each thread gets its own core
  2. B. About a quarter, because CPython uses all 4 cores
  3. C. About the same or slightly worse, because the GIL lets only one thread execute Python bytecode at a time
  4. D. Unpredictable, because the threads corrupt each other's local variables

Correct answer: C. About the same or slightly worse, because the GIL lets only one thread execute Python bytecode at a time

The Global Interpreter Lock (in the standard, non-free-threaded CPython build) serialises bytecode execution, so CPU-bound threads do not run in parallel; switching overhead can even make it slower. Use multiprocessing for CPU-bound parallelism.

More Python Programming questions

Exams that ask this topic