CS 544 — Deck 4: Compute

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/25

flashcard set

Earn XP

Description and Tags

26 cards from the official Fall 2026 CS 544 Anki Compute deck. Python Thread creation and native ID examples corrected. Source: https://tyler.caraza-harter.com/cs544/f26/anki.html

26 Terms

1
New cards

There is one virtual address space per _______

process

2
New cards

A process is a running ______

program

3
New cards

Virtual memory maps to ______

physical memory

4
New cards

Which address space can contain "holes" (invalid addresses)

Virtual address spaces can have holes (physical address spaces do not -- they are contiguous)

5
New cards

What are three things that go in a virtual address space?

code stack heap

6
New cards

Which pointer indicates what code to execute next?

The "instruction pointer"

7
New cards

There is one stack per _____ and one heap per ______

thread, process

8
New cards

What is it called when the scheduler stops running one thread and starts running a different one?

A "context switch"

9
New cards

What are three states a thread can be in?

running, blocked, ready

10
New cards

What are some reasons a thread might be blocked?

waiting on user input, disk operations, network operations, timer sleep, etc.

11
New cards

How do you create and launch a thread object for running function f(x)?

t = threading.Thread(target=f, args=(x,)); t.start() [Corrected Python API: target and args belong in Thread(), not start().]

12
New cards

How do you wait for a thread t to finish running?

t.join()

13
New cards

How can you print a thread's ID?

For the calling thread: threading.get_native_id(). For a started Thread object t: t.native_id. [Corrected Python API.]

14
New cards

What is a "race condition"

A bug that only sometimes surfaces, depending on when context switches happened between threads

15
New cards

When might a context switch occur?

Between instructions -- a single line of code might correspond to multiple bytecodes or machine instructions, so it's important to note that context switches often occur in the middle of a line of code being executed.

16
New cards

What is a "race condition"?

A bug, where whether or not you get correct behavior depends on how threads get scheduled. Race conditions are tricky to test+debug because they're non-deterministic (not same behavior each time), and you might only see the incorrect behavior rarely (say one in a million times).

17
New cards

What is "deadlock"?

This is when threads can never make progress, because they each want to acquire a lock that will never be released. One example: t1 has A and t2 and B; t1 is waiting to additionally acquire B, and t2 is waiting to additionally acquire A. This will never happen because neither thread will release its first lock until it has acquired the second lock and done some work.

18
New cards

How can a thread (a) get a lock and (b) let go of it?

lock.acquire() lock.release()

19
New cards

How can you rewrite the following code so that the release will happen, even if an exception occurs? lock.acquire() # code with possible exception lock.release()

with lock: # code with possible exception

20
New cards

What do you call a section of code where certain interleavings with other code would be a problem?

critical section

21
New cards

What is "atomicity" in the context of multi-threaded programs?

If a thread is changing multiple things together, we never want to see (say from another thread) partial results, with only some changes made.

22
New cards

What is an "invariant"?

A rule that applies to the data, often something a human might know from context. For example, an invariant might be a list of ages cannot contain negative numbers. Some invariants are known by the system (for example, that the length of the list itself cannot be negative).

23
New cards

What is "consistency" in the context of threading?

All invariants are enforced.

24
New cards

If thread t1 holds a lock, what could happen? 1. we could context switch to another thread t2 2. another thread t2 could acquire the lock

(1) is possible, (2) is not

25
New cards

What happens in Python when you try to release a lock that has already been released?

There is an exception

26
New cards

What is the GIL?

Global Interpreter Lock