1
$\begingroup$

I have seen many solutions to critical section problems in process synchronization chapter . Many of them first acquire resources , execute critical section and leave . My Question is a process exiting from the critical section should always call $V(S)$ (or release/signal/ up ) instruction ? Can any process exit from critical solution by calling wait instruction ? If so give an example and explain how it works .

For example , all the problems regarding semaphore are executed in the following manner . Where $P(s) $ and $V(s)$ has usual meaning .( up and down operator )

s=1
P(s)
< Critical Section >
V(S)

I have never seen an solution like this

s=0
V(s)
< Critical Section >
P(S)

Does any critical section problems could be solved like this ? if so please explain me how it would works .

$\endgroup$
  • $\begingroup$ What is $V(S)$? Please make your question self contained and provide definitions for the notations you're using. $\endgroup$ – Ariel Oct 22 '16 at 15:43
  • 1
    $\begingroup$ @Ariel V(S) is a common notations used in Process synchronization i thought everyone will knew it . Sorry will replace it $\endgroup$ – pC_ Oct 22 '16 at 15:45
  • $\begingroup$ Your question is still not well defined, how should one interpret "release" instruction without any context? What king of synchronization primitives are allowed? how many processes? are there any limitations on shared memory? If a process took some resources in order to enter the critical section, it makes sense he should give them back afterwards, but without exact constraints on the synchronization algorithms were talking about we cant say much (e.g. Dekker's algorithm uses three shared variables, the notion of "release" there is switching boolean values). $\endgroup$ – Ariel Oct 22 '16 at 15:53
  • $\begingroup$ If one uses a binary semaphore, the notion of "release instruction" is the semaphore release command. The two type of "release" are very different (between this and Dekker's algorithm), so without formal definitions we cant really say anything. $\endgroup$ – Ariel Oct 22 '16 at 15:56
  • $\begingroup$ @Ariel Oops Sorry. I never knew these many concepts exists in semaphor chapter. I will try to be more specific $\endgroup$ – pC_ Oct 22 '16 at 16:43
2
$\begingroup$

Assuming s is a binary semaphore.

If s=0, a V(s) will be successful operation making s=1

If s=1, a V(s) will be successful operation making s=1

If s=0, a P(s) will be unsuccessful operation by retaining s=0

If s=1, a P(s) will be successful operation by making s=0

s=0
V(s)
< Critical Section >
P(s)

Let process ${p_1,p_2,p_3,.,p_k,.,p_n}$ are waiting go get a chance to access CS (Critical Section).

For the first time $p_1$ tries V(s), successfully increase s by 1,and get an access to CS.

While $p_1$ still in CS $p_k$ tries V(s), successfully increase s by 1 and get an access to CS and so on.

With V(s) at the entry of the CS, will never guarantee blocking others from getting into CS.

With this implementation all process waiting to access CS will get into CS, thus violation mutual exclusion.

Here talking about exiting operation P(s) is useless as it doesn't help the event by any means.

s=1
P(s)
< Critical Section >
V(s)

Here, if $p_1$ tries P(s) for the first time, successfully decease s by 1 and get access to CS.

With P(s) at the entry of the CS, will guarantee blocking others from getting into CS.

While $p_1$ still in CS $p_k$ tries to enter CS by executing P(s), but fails as s=0 already and cant decrease anymore.

Thus always guarantee mutual exclusion.

See what happens if we doesn't have signal operation at CS exit:

s=1
P(s)
< Critical Section >
// remove exit operation V(s)

Without $p_1$ signaling, non of the waiting process ${p_2,p_3,.,p_k,.,p_n}$ can access CS. no one can execute the entry operation P(s),since 's' value is still 0.

All processes waiting for CS will be blocked infinity.

Thus, deadlock kind of event happens here where resource is available but cant be accessed.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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