rgamber
rgamber

Reputation: 5849

Threads and Processes

I am trying to revise my Operating System concepts, but I had some confusions. I know that a process is a thread with its own address space.

1) Are deadlocks only caused by threads or processes? (Threads share the process's stack, where as different processes have different stacks).

2) Can a single process cause a deadlock? or does it take more than one process for a deadlock to occur?

I am not sure if this is the right place to ask this. If not, please let me know and I will delete the question.

Upvotes: 0

Views: 181

Answers (2)

Nokia808Freak
Nokia808Freak

Reputation: 921

The answer lies in your Question itself. Each Process has a stack and all the threads created by the process share the stack. whenever two threads of the same process request for a resource(data,comm,...) that other threads has a lock to and in-turn waits for a release of other resource then deadlocks occur.

answer:
for 1):
threads cause deadlocks within process and process cause deadlocks within parent process (in most situations OS)
for 2):
yes a single process can cause deadlocks.

Upvotes: 2

JosephH
JosephH

Reputation: 8815

Both threads AND processes can get into deadlocks depending on what they are trying to lock. If the resource that they want to lock is a resource that's shared within a process (e.g. critical section), threads can get into deadlock. On the other hand if it's a resource that's shared globally (e.g. named mutex), processes can get into a deadlock. For 2), there must be more than one process involved since more than one process must try to lock (globally) shared resource in order for a deadlock to occur.

Upvotes: 2

Related Questions