OA. free
Free
Fujitsu Data Structures & Algorithms Data Structures & Algorithms Medium

In Python, which of the following is true about the Global Interpreter Lock (GIL)?

Fujitsu technical mcq question, verified with a worked answer. Free to practise - no sign-up.

In Python, which of the following is true about the Global Interpreter Lock (GIL)? fg @® Q oonroaminn sec G)+ In Python, which of the following is true about the Global Interpreter Lock (GIL)? AP time. b - A) GIL allows multiple threads to execute Python code concurrently. - B) GILis used to manage memory in Python. - C) GIL ensures that only one thread executes Python bytecode at a - D) GlLis a tool for handling exceptions in Python.

Choose one option.
Show answer & explanation
Answer: C. GIL ensures that only one thread executes Python bytecode at a

The Global Interpreter Lock (GIL) is a mutex that protects access to Python objects, preventing multiple threads from executing Python bytecodes at once. This simplifies memory management (specifically reference counting) but limits the performance of CPU-bound multi-threaded programs.

Step-by-step Derivation:
Step 1: Analyze the nature of the GIL. The GIL is a mechanism used in CPython (the reference implementation of Python) to ensure that only one thread holds control of the Python interpreter at any given time.
Step 2: Evaluate Option A. This is incorrect because the GIL specifically prevents multiple threads from executing Python code concurrently on multiple cores; it serializes execution.
Step 3: Evaluate Option B. While the GIL protects the internal state of memory management (reference counting), it is not a memory management tool itself (like a garbage collector).
Step 4: Evaluate Option C. This accurately describes the GIL's function: it acts as a lock that ensures only one thread is executing bytecode at a time, maintaining thread safety for the interpreter's internal state.
Step 5: Evaluate Option D. The GIL has no relation to exception handling mechanisms (try-except blocks).
Step 6: Conclusion: Option C is the technically correct definition.