NEW CD SET 2

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

1/13

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 9:41 PM on 8/4/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

14 Terms

1
New cards

What is the similarity between sleep() and yield()?

Both let a thread pause without releasing its locks, and neither blocks on a condition.

2
New cards
What are the 4 necessary conditions for deadlock?
The four conditions are mutual exclusion, hold and wait, no pre-emption, and circular wait.
3
New cards
Why can't semaphores generally be used as locks?
Semaphores don't check ownership, so any thread can call release(), even one that never called acquire().
4
New cards
Describe the classic 3-state thread model and its transitions.

The three states are Ready, Running, and Blocked. The scheduler swaps a thread between Ready and Running, and I/O or lock waits before sending it to blocked

5
New cards
What does tryLock() do?
tryLock() grabs the lock only if it's free right now, returning true or false immediately instead of blocking.
6
New cards
What's the difference between coarse-grained and fine-grained locking?

Coarse-grained locking uses one lock for everything, but serializes all access. Fine-grained gives each element its own lock for more concurrency, at the cost of complexity.

7
New cards
What is the difference between a process and a thread?
A process has its own memory space. Threads share memory within a process, which makes sharing easy but risky without sync.
8
New cards
How do you get a list of IP addresses assigned to a network interface in Java?
Call NetworkInterface.getNetworkInterfaces() to list interfaces, then getInetAddresses() on each for its IPs.
9
New cards
What is the difference between a Predicate and a Function?
A Predicate's test() always returns a boolean. A Function's apply() can return any type.
10
New cards

What is the purpose of a synchronized block?

A synchronized block guarantees mutual exclusion and visibility between threads.

11
New cards

Explain how CompareAndSwap works?

CAS atomically compares a memory location to an expected value. If they match it swaps in new values. if not it does nothing and retires

12
New cards

When is it better than locks?

CAS is better than locks under light contention, since a failed thread just retries instead of blocking

13
New cards

two reasons threads are better than processes

Threads share memory directly, so no IPC is needed. Threads are also cheaper to create and context switch.

14
New cards

Why cant semaphores be used as locks, expect in one condition

No ownership check. Any thread can release, even one that never called acquire. Only safe as a lock when the same thread does both