Explain the difference between a process and a thread. How do they share memory in a C++ application?

Last updated 21 June 2026

A process is an independent program with its own private virtual address space; a thread is a unit of execution that runs inside a process. Threads of the same process share that address space, so they share memory by default, while processes are isolated.

  • Process:

    • Owns its address space, file descriptors, and resources; crashing one usually doesn't affect others.

    • Inter-process communication needs explicit mechanisms (pipes, sockets, shared memory segments).

  • Thread:

    • Has its own stack and registers but shares heap, globals, and code with sibling threads.

    • Created in C++ via std::thread / std::jthread; cheaper to create and switch than a process.

  • Sharing memory in C++:

    • Threads access the same heap objects and globals directly, which is why synchronization (std::mutex, std::atomic) is required to avoid data races.

    • Unsynchronized concurrent access where at least one is a write is undefined behavior.

  • https://www.interviewbit.com/cpp-interview-questions/
  • https://hellointern.in/blog/multithreading-interview-questions-and-answers-for-5-years-experience-71300
  • https://www.scribd.com/document/941388620/Linux-Interview-QA-for-CPP-Developers-2025
  • https://github.com/Nabagata/interview-prep
  • https://www.geeksforgeeks.org/operating-systems/operating-systems-interview-questions/
All C++ interview questions