• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 15 pages
Exam (elaborations)

Purdue CS 252 Final Study Guide Exam With Complete Solutions

Document preview thumbnail
Preview 2 out of 15 pages

Purdue CS 252 Final Study Guide Exam With Complete Solutions...

Content preview

Purdue CS 252 Final Study Guide Exam
With Complete Solutions



thread - ANSWER Path of execution. By default, each program has a main
thread that executes main().

Every thread has its own...
Stack
PC - Program Counter
Set of registers
State

What are some of the application of threads? - ANSWER Threads help
divide up the work, can be used in applications like servers. This leads to a
faster overall completion time if they are doing independent tasks.

What are the advantages of threads? (versus processes) - ANSWER *Fast
thread creation* - creating a new path of execution is easier.
*Fast context switch* - context switch across threads is faster than across
processes.
*Faster communication* - fast & easy to talk between threads. (processes
require pipes, etc).

What are the disadvantages of threads? (versus processes) - ANSWER
*Threads are less robust* - if one thread crashes, the entire application will
crash. If one process crashes, all other processes remain running.
*More sync problems* - Since threads modify the same global variables at
the same time, they may corrupt data structures. Synchronization is
required.

, What is an atomic section of code? - ANSWER A portion of code that only
one thread should execute at a time, while the other threads wait.
Sometimes called a "critical section".

What are mutex locks? - ANSWER Mutex locks are software mechanisms
that enforce atomicity. They enforce mutal exclusion of two or more
sections of code if the same lock is used.

What are the two mutex lock implementations? - ANSWER *Disable
interrupts*: Used only in Kernel mode, so that context switches cannot
happen. May lose interrupts and can be slow.
*Spin locks*: Can be implemented in user space, rely on the test_and_set
assembly instruction (since it is guaranteed atomic).

What are spin locks? - ANSWER A type of lock that rely on the
test_and_set assembly instruction, which is guaranteed to be atomic.
Mutex locks are implemented on top of spin locks.

Spin locks makes the thread "spin", or keep checking a while loop, rather
than putting the thread to sleep.

What are the advantages and disadvantages of spin locks? - ANSWER
*Advantages*
- Does not have any system overhead since the threads are not being put
to sleep
- Easy to implement, can be used in small sections that take a short
amount of time.

*Disadvantages*
- Spin locks do not enforce fairness, whichever thread unlocks it can use it.
There is no FIFO queue.
- Clock cycles are wasted since the threads do not do anything besides
"spin".

What is the difference between calling yield() in a spin lock versus nothing?
- ANSWER If we decide to call pthread_yield(), we are checking the
condition once, then devoting the rest of our clock cycles to other
processes. There is no need for the thread to constantly check the
condition of the lock, it can do so on the next quantum. Thus, if we use the
yield command, the thread that has the lock can complete more work,

Document information

Uploaded on
August 24, 2026
Number of pages
15
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$17.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Zayla
3.2
(20)
Sold
162
Followers
13
Items
18435
Last sold
1 day ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions