Creating new threads is less time consuming and less resource intensive compared to creating
new processes. Threads share a PMI (process memory image) within a process, while
processes run on different memory segments. Threads run within a process.
Threads share data, processes don't (easily) share data.
Threads share everything in the PMI but not the stack and context. - ANS-How do threads differ
from processes?
Creating a new thread within a program does not create a new PMI.
Because threads share the same memory, context switching is more efficient than between
processes. - ANS-Why is it more expensive to create a new process compared to creating a
new thread?
Many user-level threads mapped to a single kernel thread* . Thread management is done by the
thread library in user space.
*Threads mapped to a single kernel thread meaning they are scheduled as a single process by
CPU. - ANS-In short, explain the many-to-one user level thread model.
Thread management is done by the thread library in user space but the entire process will block
if a thread makes a blocking system call. Only one thread can access the kernel at a time,
hence threads cannot run in parallel on multiprocessors. ONE BLOCKS ALL - ANS-Explain
what happens if one of the threads makes a blocking system call in the many-to-one user level
thread model.
Atomic operations in concurrent programming are program operations that run completely
independently of any other processes
An atomic operation is an operation that will always be executed without any other process
being able to read or change state that is read or changed during the operation
‣ Additionally, atomic operations commonly have a succeed-or-fail definition—they either
successfully change the state of the system, or have no apparent effect. - ANS-What is meant
by an atomic operation?
counter = counter + 1 - ANS-Give examples of non-atomic operations
A race condition or race hazard is the behaviour of an electronic, software or other system
where the output is dependent on the sequence or timing of other uncontrollable events. It
becomes a bug when events do not happen in the intended order. - ANS-Define Race condition
A data race occurs when two instructions from different threads access the same memory
location and:
‣ at least one of these accesses is a write