Interview Topics: URL Processing, TLS Handshake, TCP Handshake, Page Fault, TCP vs UDP, HTTP Differences, Thread Safety in C++, and Thread‑Pool Implementation
This article reviews common interview questions covering URL request processing, TLS handshake steps, the three‑way TCP handshake and four‑way termination, page‑fault handling, differences between TCP and UDP, HTTP/1.0 vs 1.1, thread‑safety mechanisms in C++, and a hands‑on example of building a thread pool.
In a casual interview‑style discussion, the author presents a series of technical questions and answers that span networking, operating‑system concepts, and concurrent programming in C++.
1. URL processing steps
User enters a URL in the browser.
DNS resolution to obtain the server's IP address.
TCP three‑way handshake to establish a connection.
Browser sends an HTTP request.
Server processes the request (e.g., database query, business logic).
Server returns an HTTP response.
Browser receives and renders the page.
Resources may be cached for future visits.
2. TLS handshake
Client initiates connection and receives server certificate.
Server and client perform key exchange using public‑key cryptography.
Both sides derive a symmetric session key and encrypt subsequent traffic.
Data is transmitted securely.
Connection is closed when finished.
3. TCP three‑way handshake and four‑way termination
The three‑way handshake (SYN, SYN‑ACK, ACK) is required to synchronize sequence numbers and confirm both sides are ready; a two‑step process would leave one side unaware of the other's initial sequence.
Four‑way termination (FIN, ACK, FIN, ACK) ensures each direction of the full‑duplex channel is closed independently, guaranteeing that all in‑flight data is received before the connection is fully closed.
4. Page fault in operating systems
CPU receives a page‑fault interrupt and switches to kernel mode.
Kernel checks the page table for the faulting address.
If the page is not resident, the OS selects a free frame, reads the page from disk, updates the page table, and resumes the faulting instruction.
5. TCP vs UDP
TCP provides connection‑oriented, reliable, ordered delivery with flow control and congestion control.
UDP is connectionless, best‑effort, low‑overhead, suitable for real‑time or loss‑tolerant applications.
Typical TCP use cases: web browsing, file transfer, email.
Typical UDP use cases: live audio/video, online gaming, DNS queries.
6. Thread‑safety mechanisms in C++
Mutex ( std::mutex) with std::lock_guard for exclusive access.
Read‑write lock ( std::shared_mutex) for multiple readers, single writer.
Atomic operations ( std::atomic) for lock‑free counters.
Condition variable ( std::condition_variable) for thread coordination.
#include <iostream>
#include <thread>
#include <mutex>
std::mutex mtx;
void threadFunction() {
std::lock_guard<std::mutex> lock(mtx);
// access shared resource
}
int main() {
std::thread t1(threadFunction);
std::thread t2(threadFunction);
t1.join();
t2.join();
return 0;
}7. HTTP/1.0 vs HTTP/1.1
Persistent connections are default in HTTP/1.1, reducing connection overhead.
Pipeline support in HTTP/1.1 allows multiple requests without waiting for responses.
Enhanced cache control headers (Cache‑Control, ETag, If‑Modified‑Since).
Host header introduced for virtual hosting.
Additional status codes and header fields (Range, Content‑Length, chunked transfer, etc.).
8. Hand‑crafted thread pool in C++
Key steps:
Define an abstract Task class with a virtual execute() method.
Create a ThreadPool class that holds worker threads, a task queue, a mutex, and a condition variable.
Implement the constructor to spawn the desired number of worker threads, each looping to fetch and execute tasks until a stop flag is set.
Provide an addTask(Task* task) method that pushes tasks onto the queue and notifies a worker.
In main(), instantiate ThreadPool pool(4) and enqueue several tasks.
class Task {
public:
virtual void execute() = 0;
};
#include <vector>
#include <thread>
#include <queue>
#include <mutex>
#include <condition_variable>
class ThreadPool {
public:
ThreadPool(size_t numThreads);
~ThreadPool();
void addTask(Task* task);
private:
std::vector<std::thread> workers;
std::queue<Task*> tasks;
std::mutex queueMutex;
std::condition_variable condition;
bool stop;
};
ThreadPool::ThreadPool(size_t numThreads) : stop(false) {
for (size_t i = 0; i < numThreads; ++i) {
workers.emplace_back([this] {
while (true) {
Task* task = nullptr;
{
std::unique_lock<std::mutex> lock(queueMutex);
condition.wait(lock, [this] { return stop || !tasks.empty(); });
if (stop && tasks.empty()) return;
task = tasks.front();
tasks.pop();
}
task->execute();
delete task;
}
});
}
}
ThreadPool::~ThreadPool() {
{
std::unique_lock<std::mutex> lock(queueMutex);
stop = true;
}
condition.notify_all();
for (std::thread &worker : workers) {
worker.join();
}
}
void ThreadPool::addTask(Task* task) {
{
std::unique_lock<std::mutex> lock(queueMutex);
tasks.push(task);
}
condition.notify_one();
}
int main() {
ThreadPool pool(4);
for (int i = 0; i < 8; ++i) {
pool.addTask(new YourTask()); // YourTask derives from Task
}
return 0;
}The author concludes with a light‑hearted note encouraging readers to review such interview material during the holiday season.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
IT Services Circle
Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
