0
$\begingroup$

In a system, suppose there is a process and a resource with only one instance.

Let us assume that the process holds the instance and requests the same instance of that resource. Will there be a deadlock? Under what circumstances?

$\endgroup$

closed as unclear what you're asking by D.W., David Richerby, Juho, Rick Decker, Hoopje Nov 11 '14 at 18:17

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ What do you think? What have you tried for the second question and where did you get stuck? What is the locking mechanism you assume? $\endgroup$ – Raphael Nov 10 '14 at 13:11
4
$\begingroup$

Resources that can only be used by a single process at a time are usually protected by a lock. If the process that currently holds the lock attempts to acquire it a second time, what happens depends on the type of lock.

  • If the lock is reentrant, then it can be acquired multiple times by the same process. The process will need to call the release function as many times as it called the acquire function.
  • If the lock is not reentrant (for example if it's a simple semaphore or an atomically-modified boolean), then a second attempt will block. You can call this a single-process deadlock.
  • In some mutex implementations (probably not in what is studied in Concurrency 101 though), a process can acquire the same lock more than once, and the second time is a no-op, so the process must only call the release function once. Another thing that sometimes happens is that calling the acquire function from the same process twice puts the implementation in a bad state after which anything can happen — the semantics doesn't define what happens in that case.

Thus, it depends on what semantics your locks have. You can build non-reentrant locks on top of reentrant locks or vice versa if all you have is the wrong kind for what you want to do.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.