The Process and Thread are the essentially associated. The process is an execution of a
program whereas thread is an execution of a program driven by the environment of a process.
Don't use plagiarized sources. Get Your Custom Essay on
Question: List references where needed 1. Describe the difference between a process and a thread 2. Which o……
Get an essay WRITTEN FOR YOU, Plagiarism free, and by an EXPERT!
Another major point which differentiates process and thread is that processes are isolated with
each other whereas threads share memory or resources with each other.
The main key difference between process and thread are below:
All threads of a program are logically contained within a process.
A process is heavy weighted, but a thread is light weighted.
A program is an isolated execution unit whereas thread is not isolated and shares memory.
A thread cannot have an individual existence; it is attached to a process. On the other hand,
a process can exist individually.
At the time of expiration of a thread, its associated stack could be recovered as every thread
has its own stack. In contrast, if a process dies, all threads die including the process.
Its Heap Memory.
Global variables are also shared but they are dependent on the platform.
Registers and stacks are specific to their own threads so can’t be shared.
In a loop a thread waits simply (‘spins’) checks repeatedly until the lock becomes available.
This type of lock is a spin lock. The lock is a kind of busy waiting, as the threads remains active by not performing a useful task.
The spin locks are to release explicitly, although some locks are released automatically when the tread blocks.
The primary disadvantage of a spinlock is that, while waiting to acquire a lock, it wastes time that might be productively
spent elsewhere. There are two ways to avoid this:
Do not acquire the lock. In many situations it is possible to design data structures that do not require locking,
e.g. by using per-thread or per-CPU data and disabling interrupts.
Switch to a different thread while waiting. This typically involves attaching the current thread to a queue of
threads waiting for the lock, followed by switching to another thread that is ready to do some useful work.
This scheme also has the advantage that it guarantees that resource starvation does not occur as long as all
threads eventually relinquish locks they acquire and scheduling decisions can be made about which thread should progress first.
Spinlocks that never entail switching, usable by real-time operating systems, are sometimes called raw spinlocks.
A critical section in which the process may be changing common variables, updating table, writing a file and perform
another function. The important problem is that if one process is executing in its critical section, no other process
is to be allowed to execute in its critical section. Each process much request permission to enter its critical section.
A semaphore is a tool for synchronization and it is used to remove the critical section problem which is that no two
processes can run simultaneously together so to remove this two signal operations are used named as wait and signal
which is used to remove the mutual exclusion of the critical section. as an unsigned one of the most important
synchronization primitives, because you can build many other Decrementing the semaphore is called acquiring or locking it,
incrementing is called releasing or unlocking.
A mutex is a special case of the semaphore and also known as binary mutex it can have only two values minimum of 0 and
maximum of 1, meaning it can be either locked or unlocked. It is used to prevent more than one thread from accessing the
same data while allowing multiple threads to run on it.
A Monitor is an object designed to be accessed from multiple threads. The member functions or methods of a monitor object
will enforce mutual exclusion, so only one thread may be performing any action on the object at a given time. If one thread
is currently executing a member function of the object then any other thread that tries to call a member function of that
object will have to wait until the first has finished.
A Semaphore is a lower-level object. You might well use a semaphore to implement a monitor. A semaphore essentially is just
a counter. When the counter is positive, if a thread tries to acquire the semaphore then it is allowed, and the counter is
decremented. When a thread is done then it releases the semaphore, and increments the counter.
If the counter is already zero when a thread tries to acquire the semaphore then it has to wait until another thread releases
the semaphore. If multiple threads are waiting when a thread releases a semaphore then one of them gets it. The thread that
releases a semaphore need not be the same thread that acquired it.
A monitor is like a public toilet. Only one person can enter at a time. They lock the door to prevent anyone else coming in, do their stuff, and then unlock it when they leave.
A semaphore is like a bike hire place. They have a certain number of bikes. If you try and hire a bike and they have one free then you can take it, otherwise you must wait. When someone returns their bike then someone else can take it. If you have a bike then you can give it to someone else to return — the bike hire place doesn’t care who returns it, as long as they get their bike back.