Lecture_8-CSCIU511-Jahangir_Majumder-Spring_2025

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/14

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 7:30 AM on 2/10/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

15 Terms

1
New cards

What is the primary purpose of thread synchronization?

To allow concurrent accesses to variables while removing non-deterministic outcomes by enforcing the order of thread execution.

2
New cards

What outcomes are acceptable for concurrent reads and writes?

Multiple concurrent reads are acceptable, but multiple concurrent writes and one write with multiple reads are not acceptable due to non-deterministic outcomes.

3
New cards

What is a race condition?

A situation where the output of a concurrent program depends on the order of operations between threads.

4
New cards

What is a critical section?

A piece of code that accesses shared variables and must be executed by only one thread at a time.

5
New cards

What are the two methods associated with locks?

Lock::acquire() and Lock::release().

6
New cards

How does a lock function in relation to mutual exclusion?

A lock can either be BUSY or FREE; at most one thread holds the lock at any time.

7
New cards

Provide an example of how a race condition can manifest in a program involving two threads setting a variable x.

Thread 1 sets x=1; Thread 2 sets x=2; the final value of x can be either 1 or 2 depending on which thread executes first.

8
New cards

What is the result of the race condition example with two threads, Thread 1 and Thread 2, where Thread 1 reads y and Thread 2 updates y?

The final value of x can either be 13 or 25 depending on which thread executes first.

9
New cards

In the 'Too Much Milk' example, what correctness properties need to be addressed?

At most one person buys milk (safety) and someone buys milk if needed (liveness).

10
New cards

What can happen in 'Too Much Milk' Try #2 where both threads leave their own notes?

Starvation can occur, where one thread might wait indefinitely.

11
New cards

What does the entry section in a critical section involve?

Locking before entering the critical section and waiting if the lock is already taken.

12
New cards

What is a lock's state when it is first initialized?

The lock is initially in the FREE state.

13
New cards

What is the purpose of using locks in concurrent programming?

To ensure that shared data is accessed by one thread at a time, preventing data corruption.

14
New cards

What precautions should be taken when using locks?

Always acquire the lock before accessing shared data and release it after you're done.

15
New cards

Explain the dangers of not using locks when accessing shared data.

Accessing shared data without locks can lead to data corruption and unpredictable behavior.