Przejdź do treści głównej
⚡
← Kursy›Senior Deep-DivesModuł 1 · Współbieżność i asynchroniczne elementy wewnętrzne›GIL — czym jest, czym nie jestpredict2 / 161
+75 XP
Zadanie
📝 **Zadanie:** Przewiduj trzywierszowy werdykt, jaki wyświetli fragment kodu — po jednej linii na każdy rodzaj obciążenia, w pokazanej kolejności. 📋 Zaimplementuj powyższą funkcję. Testy uruchamiają się automatycznie. 💡 **Wskazówka:** Jeśli utkniesz, przeczytaj ponownie teorię.
Przewiduj wynik

Przeczytaj kod uważnie

# Each function reports whether moving from 1 thread to 4 threads
# in CPython would yield a real speedup. The verdict is decided
# by the GIL rules, NOT by wall-clock measurement.

def cpu_bound():
    # Pure Python tight loop — GIL serializes every bytecode op.
    return "no_speedup"

def io_bound():
    # time.sleep / socket waits release the GIL.
    return "speedup"

def numpy_bound():
    # NumPy's C code releases the GIL during heavy array ops.
    return "speedup"

print(cpu_bound())
print(io_bound())
print(numpy_bound())

# What does this print? Type your prediction.

Co wypisze program? Napisz tutaj: