Vai al contenuto principale
← CorsiSenior Deep-DivesModulo 1 · Concorrenza e aspetti interni asincroniIl GIL: cos'è e cosa non èpredict2 / 161
+75 XP
Compito
📝 **Attività:** prevedere il verdetto di tre righe stampato dallo snippet: una riga per tipo di carico di lavoro, nell'ordine mostrato. 📋 Implementa la funzione sopra. I test vengono eseguiti automaticamente. 💡 **Suggerimento:** Rileggi la teoria se rimani bloccato.
Predici output

Leggi il codice attentamente

# 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.

Cosa stamperà il programma? Scrivi qui:

💬 Discussione

Sii il primo a fare una domanda o condividere un consiglio.
Accedi per partecipare alla discussione. La lettura è gratuita.
Caricamento discussione…