Purdue CS 252 Final Study Guide

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

1/105

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 9:53 PM on 5/5/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

106 Terms

1
New cards

thread

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

2
New cards

What are some of the application of threads?

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.

3
New cards

What are the advantages of threads? (versus processes)

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

4
New cards

What are the disadvantages of threads? (versus processes)

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.

5
New cards

What is an atomic section of code?

A portion of code that only one thread should execute at a time, while the other threads wait. Sometimes called a "critical section".

6
New cards

What are mutex locks?

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.

7
New cards

What are the two mutex lock implementations?

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

8
New cards

What are spin locks?

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.

9
New cards

What are the advantages and disadvantages of spin locks?

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

10
New cards

What is the difference between calling yield() in a spin lock versus nothing?

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, which produces a quicker overall time. If we do not call yield, the threads that do not have the lock waste clock cycles by constantly checking the status.

11
New cards

Do threads get duplicated when calling fork()?

Threads that have been created with pthread_create() are not duplicated except if it is the thread calling fork. (In Solaris they are duplicated however, but who cares about Solaris?)

Ex: In UNIX, if we create 5 threads using create() then call fork(), the child will only get one thread so we have a total of 6 threads.

12
New cards

What is a race condition?

A bug related to having multiple threads modifying a data structure simultaneously. Race conditions are difficult to debug.

13
New cards

What are semaphores?

Semaphores are a generalization of mutexes. Semaphores allow a maximun number of threads between a sema_wait and sema_post. The semaphore is initialized with a counter that is greater than or equal to 0.

14
New cards

When do semaphores wait?

When sema_wait is called, the count value is decremented by 1. If that new value is less than 0, then wait is called.

15
New cards

What are the three different use cases of semaphores?

Mutex: Initial counter = 1

N Resource: Initial counter is n > 1.

- If you have access to 5 printer with n=5, the 6th computer will need to wait.

Wait for event: Initial counter = 0

- All threads that call wait will block until the sema_post is called

16
New cards

Review the examples on the slides for bounded buffers, semaphores, read/write locks, and mutex locks.

May be important!

17
New cards

What are read/write locks?

They are locks for data structures that can be read by multiple threads simultaneously, but can only be modified by one thread at a time. They are fair but may suffer from starvation of writers.

18
New cards

What is deadlock?

It happens to one or more threads will have to block forever because they have to wait for a resource that will never be available. When a deadlock happens, the process will need to be killed.

19
New cards

What is starvation?

Starvation happens when a thread may need to wait for a long time before a resource becomes available.

20
New cards

How to prevent deadlocks?

Assign an order to the locks (m1, m2, ...). When we need to hold mutex lock mi, mj, where i < j lock the mutex mi and then mj.

Ex: If m1 and m3 have to be locked, lock m1 before locking m3. Note: order of unlocking does not matter.

See slides for more examples.

21
New cards

How is synchronization implemented in Java?

Java uses they keyword synchronized to denote atomic sections, no need for explicit calls to lock or unlock. Any Java object can also hold as a lock.

22
New cards

What are the different type of calls you can make on the lock object in Java?

object.wait() - The caller will wait until another thread calls notifiy/notifyAll.

object.notify() - Wake up one thread waiting.

object.notifyAll() - Wake up all threads waiting.

23
New cards

What are the different time components of a program (from the time command)?

User Time - Time spent in user mode

System Time - Time spent in Kernel mode

Real Time - Wall clock time.

24
New cards

What is the equation relating User time, System time, and Real time in a multiprocessor machine?

User time + system time < N * Real Time

(where N is the number of processors).

25
New cards

What are parallel computer systems?

These are systems in which there are more than 1 CPU in the same computer. Called SMP, or Symmetric Multiprocessing, each CPU runs a copy of the OS. If tasks are independent, a task that takes T seconds with 1 CPU now takes T/N. [but this is rarely the case since some instructions may have to be executed in order].

These are expensive however, cost is O(n^2) with number of processors.

Ex: Database servers

26
New cards

What is a cluster computer system?

A cluster is a collection of inexpensive computers connected through a fast network. The cost is linear [O(n)], which is an advantage over parallel systems. They are also more robust, since individuals can be serviced without affecting the system as a whole.

They do suffer from slow communication across nodes however. (Parallel systems are faster in this regard).

27
New cards

What are some examples of cluster computer systems?

The best example is the cluster that Google utilizes, since they leverage millions of computers distributed in different locations. Another example is rendering farms, which are used to create animated movies.

28
New cards

What is a grid computer system?

A collection of inexpensive computers across the internet running the same application to accomplish a collective task. People donate idle time of there CPU to be used on the grid.

Ex: SETI@home, BitTorrent

29
New cards

First Midterm Review!

Slide 478

30
New cards

What is the internet a collection of?

The internet is a collection of Networks, Routers interconnecting networks, and Hosts connected to networks.

31
New cards

How is the internet layered?

It reflects the layering used by the TCP/IP protocols.

Application [HTTP]

Transport [Prog to Prog, TCP and UDP]

Internet [Port Forwarding, IP]

Network Interface [LAN, Ethernet]

Physical [Basic HW]

32
New cards

What are the fundamentals of an IP Address?

As a whole, it is an abstraction to hide the network internals. It is independent from HW addressing.

It contains 32 bits, and there is a unique value for each host.

Important: An IP address does not specify a specific computer, but rather a connection between a computer and a network.

33
New cards

What are the two parts of an IP Address?

The prefix identifies a network

The suffix identifies the host in the network

34
New cards

What is a subnet mask?

A subnet mask is a parameter in the interface that tells the number of bits used for the network number.

35
New cards

What is a routing table?

A routing table lists the routes to particular destinations. The operations used to be manual when networks were small and static, but now it is done automatically and is required for larger networks.

36
New cards

Example on Slide 498

Review and re-watch lecture?

37
New cards

What is a packets "time to leave"?

It is the max time that a packet is allowed to be in a loop. The value starts at 255 and decrements after every router hop. If the count hits 0, the packet is discarded. This ensures that there are not endless packets floating around.

38
New cards

What is Address Resolution Protocol (ARP)?

When the router needs to deliver a packet directly, it is required to convert the IP to a hardware address. ARP does this translation.

39
New cards

What is stored in an ARP table/cache?

The cache (or table) stores a key value pair consisting of (IPAddr, EtherAddr) after the IP address has been resolved into a hardware address. This table is built as needed, and the values stay in the table for a set amount of time.

If the value is not in the table, it is required to broadcast across the network and ask to see what location is needed.

40
New cards

What is a DNS?

DNS is a service that translates host names to IP addresses. They use a lookup algorithm and contacts as many servers as necessary. (the cache is used to minimize lookup times however).

Host names are divided into domains:

host.dom2.dom1.dom0

ector.cs.purdue.edu

The most general domain is to the right, the most specific to the left.

41
New cards

What is Dynamic Host Configuration Protocol (DHCP)? What are the four components?

Allows connecting computers to the Internet without the need of an administrator. The four components are...

Local IP Address - Current Address

Subnet Mask - Used to send packets in same LAN

Default Router - Used to send packets outside of LAN

DNS Server - Used to convert the names to IP Addresses.

42
New cards

What are the two transport protocols?

The two available in the TCP/IP family are...

UDP - User Datagram Protocol

TCP - Transmission Control Protocol

43
New cards

What is UDP? What are some of the use cases?

User Datagram Protocol

Cons: Unreliable transfer, application will need to implement own reliability.

Pros: Benefits are minimum overhead in computation and communication. No initial setup is needed, just send and go.

Uses: LAN Applications, VOIP

44
New cards

How are messages sent in UDP?

UDP is message oriented. Each message is encapsulated in an IP datagram. The size is restricted by the Maximum Transfer Unit (MTU) of the network (MTU = 1500bytes for Ethernet).

The header has ports that identify source and destination.

45
New cards

What is TCP? What are the defining characteristics?

It is the major transport protocol used in the internet. It is...

Reliable - Uses acknowledgements and retransmission.

Connection-Oriented - An initial connection is required, both endpoints keep state.

Full-Dupex - Communication can happen in both ways simultaneously.

Stream Interface - Transfer of bytes looks like reading/writing files.

46
New cards

How does TCP achieve reliability?

It used acknowledgements and retransmissions.

47
New cards

What is an acknowledgement?

The receiver sends an acknowledgement when the data arrives.

48
New cards

What is a retransmission?

The sender starts a new timer whenever the message is transmitted. If the timer expires before an acknowledgement arrives, the sender retransmits the message.

49
New cards

What are the six important features of TCP?

1. Adaptive Retransmission

2. Cumulative Acknowledgements

3. Fast Retransmission

4. Flow Control

5. Congestion Control

6. Reliable Connection and Shutdown

50
New cards

What is Adaptive Retransmission?

This allows TCP to work in both slow and fast networks. The retransmission timer is set dynamically, using the equation...

RTT + 4*RTTSTDDEV (where RTT is the round trip time in that network).

This allows for the optimal time and timeout, so the correct amount of packets is retransmitted.

51
New cards

What is cumulative acknowledgments?

These are acknowledgements for all bytes received so far without holes (independent of packets).

52
New cards

What is fast retransmission?

It is a heuristic where a duplicated acknowledgement for the same sequence is signal of a packet lost. The data is then retransmitted before the timer expires.

53
New cards

What is flow control?

It slows down the sender if the receiver is running out of buffer space. The buffer space, or window, is sent every acknowledgement.

54
New cards

What is congestion control?

For TCP a lost packet is a signal of congestion. Instead of aggressively retransmitting, it will fisrt "slow start" and then a "congestion avoidance" where the window (buffer) of retransmittied data is reduced in size.

55
New cards

What is reliable connection and shutdown?

TCP uses a Three way handshake to close connections. Three packets are enough to make sure that lost packets will not interfere with future connections.

56
New cards

When should you use UDP?

Since UDP is unreliable, it should only be used in certain situations. Broadcasting (contacting all computers on LAN), Realtime Data: VOIP, Teleconferencing, any application where minimum delay is more important.

57
New cards

What is a Network Address Translation (NAT)?

A NAT is used when you want to connect multiple computers to the Internet using a single IP address. From the POV of the internet, all computers have the same address (which points to the NAT box).

58
New cards

What are the benefits of using a NAT?

As a side effect, NAT provides protection. The NAT is also called a Firewall, since packets will only be allowed in if that connection was started from inside the NAT.

59
New cards

How is a TCP connection uniquely defined?

It is defined by four values.

60
New cards

How does a NAT box work? What are the steps?

Review the examples of NAT box on the slides!

61
New cards

What are the different types of server concurrency?

Iterative

Fork Process

Create New Thread

Pool of Threads

Pool of Processes

62
New cards

What are relational databases? How are they constructed?

Relational databases store the information in tables. A table is made of rows and columns, where one row stores a record and a column stores an attribute of that record.

63
New cards

What is Structured Query Language (SQL)?

SQL is the standard language used to manipulate databases.

64
New cards

What are the three different SQL databases? Why are they used?

MySQL -> Free/Popular

Orace -> Enterprise

Microsoft SQL -> Microsoft product integration

65
New cards

What is a primary key?

One or more of the columns in the table can be dedicated as a primary key. The value is recommended to be unique, and a "B-tree" (like 2-3, but can have many children) is uses to search [O(log(n)) time].

66
New cards

How to select in SQL?

SELECT * FROM Books (will return all rows from Books table)

SELECT Price, Title FROM Books (return a table with only the price and title).

67
New cards

What does the WHERE feature do in SQL?

WHERE will put constraints on your query. Ex: WHERE Price <= 29.95 will only return entries that are less than 29.95 in price.

68
New cards

What does % and _ mean in SQL?

% -> Zero or more characters

_ -> any single character

69
New cards

How do you update entries in SQL?

UPDATE table SET Price = 10 ..., use the UPDATE command by first specifying the table and then selecting which fields to update.

70
New cards

How do you delete entries in SQL?

DELETE FROM table WHERE Title Like "%C++%", this deletes all entries in Books that contain C++ in their title.

71
New cards

How do you add a new entry into a SQL database?

Use INSERT to insert a new row in the table.

INSERT INTO Books VALUES(...). This creates a new entry with the values defined.

72
New cards

Who is Joel Spolsky?

Joel is a software developer who has written several books on software engineering. He created Stack Overflow.

73
New cards

What are the main components of Joel's test?

1. Source Control

2. Easy

3.Daily Build

4. Bug DB

5. Fix Bugs before new code

6. Up to date schedule

7. Project spec

8. Quiet Working conditions

9. Best tools

10. Testers

11. Code during interview

12. Hallway usability testing

74
New cards

What is Extreme (XP) Programming?

It is a practical methodology for software development. It gives a list of rules that have been successful, encourages iterative approach.

75
New cards

When should XP programming be used?

It is for projects that have some risk of completion (design changes continuously). Best for small groups, but requires good communication.

76
New cards

What is source control?

Source control will allow multiple developers to modify the same source code. It keeps track of changes, so you can always revert.

77
New cards

What are some of the different source control programs?

CVS (oldest)

SVN (rewrite of CVS, central repo)

Mercurial (Distributed, no need for central repo)

GIT (Distributed, fast)

78
New cards

What are some of the uses of source control?

Keep track of changes for multiple programmers, easy merging, go back in time, backup, peer review changes

79
New cards

How does centralized source control work (like SVN)?

There is one central repository that users can either push or pull from. There is only this location, all history is stored there.

80
New cards

How does distributed source control work?

There is no central repo, rather each programmer will have a local one. They can exchange changes without the need for a central repo.

81
New cards

How does Centralized vs Distributed Source Control compare?

Both work, but Distributed is better for when code needs to be worked on for a long time without submitting common code.

82
New cards

Why are tests important?

They are the most practical way to improve the quality of a program.

83
New cards

Who writes the tests?

Programmers write tests to verify software works as expected, tests the inner workings.

QA team tests like a black box and is independent from the development.

84
New cards

What are unitests?

Unitests are a group of tests that specify a specific class. Every class should have unitests, written by programmers.

85
New cards

What are system tests?

They test a specific subsystem of the product, can involve multiple classes. Written by programmers and QA.

86
New cards

What are regression tests?

These are tests written to reproduce a bug and also verify the bug has been fixed. Add to lists of overall tests to run, and run after every build. Written by QA and programmer.

87
New cards

What are acceptance tests?

These tests evaluate the software before a release. The tests tell if the product is ready for prime time or not. Written by QA.

88
New cards

When should tests be run?

After writing and committing new code, during the daily build. This will ensure new code does not break everything [but it is expected that it will].

89
New cards

Should we track bugs?

Yes! Tracking bugs is crucial to the success of a program.

90
New cards

What is the bug cycle?

1. Create a bug report

2. Manager assigns priority and severity.

3. Assign the bug to programmer.

4. Analyze and estimate time.

5. Fix bug and create regression tests.

6. Submit code for review.

7. QA ensures that it is fixed.

8. Close bug.

91
New cards

Why is refactoring important?

Very seldom will you start code from scratch. It is important to read and maintain code.

92
New cards

What are some things that should be refactored?

Duplicate Code, Large Class, Inconsistent Naming, Dead Code, Too General.

93
New cards

What is a software pattern?

They are reusable design solutions to reoccurring problems. They are modeled after architectural design.

94
New cards

What is synopsis, context, and forces for the proxy pattern?

S: Forces method call to an object to occur throgh a proxy object.

C: Proxy may give the illusion that the object is local, when really it is on a remote machine (can act as a logger or cache).

F: We want to add functionality to an object without modifying the object.

95
New cards

What is the solution and consequence of the proxy pattern?

S: Both proxy and service-providing object can inherit from a common class, or implement a common interface.

C: Service-providing object is used transparent to the object.

96
New cards

What is synopsis, context, and forces for the command pattern?

S: Encapsulate commands in objects so you can control sequencing, can undo or manipulate.

C: Graphics editor, want to undo a command. You can remove it from the list and play all other commands before it.

F: Need undo/redo management, can be stored for future testing or recovery.

97
New cards

What is the solution and consequence of the command pattern?

S: Create an abstract interface with do() and undo() methods. Have command objects implement abstract interface. Command manager stores commands in queue and does operations.

C: Flexibility and replay commands at any time.

98
New cards

What is synopsis, context, and forces for the observer pattern?

S: Allow to dynamically register dependencies between objects, so when one changes, the other is notified.

C: You have a directory viewer, need listener. You have a button in a GUI, register a listener. (e.g. Swing or GTK).

F: An instance of one class needs to notify an instance of another.

99
New cards

What is the solution and consequence of the observer pattern?

S: Implement a Listener abstract class, the observer implements this interface and registers itself as a listener of the observable object.

C: Cyclic dependencies may arise.

100
New cards

What is synopsis, context, and forces for the visitor pattern?

S: When you need to do operations in a complex structure, you can separate the operations from the structure by using a visitor class.

C: Want to separate the way a collection is implemented from they way you iterate over it (e.g. Iterator).

F: There are a variety of operations that need to be performed on that structure.