I came across following problem:

A certain computation generates two arrays

`a`

and`b`

such that`a[i]=f(i)`

for`0 ≤ i < n`

and`b[i]=g(a[i])`

for`0 ≤ i < n`

. Suppose this computation is decomposed into two concurrent processes X and Y such that X computes the array`a`

and Y computes the array`b`

. The processes employ two binary semaphores`R`

and`S`

, both initialized to zero. The array`a`

is shared by the two processes. The structures of the processes are shown below.`+-------------------------+-------------------------+ | Process X: | Process Y: | | private i; | private i; | | for (i=0; i < n; i++) { | for (i=0; i < n; i++) { | | a[i] = f(i); | EntryY(R, S); | | ExitX(R, S); | b[i]=g(a[i]); | | } | } | +-------------------------+-------------------------+`

How to correctly implement

`ExitX()`

and`EntryY()`

?

The given solution was:

`+---------------+----------------+ | ExitX(R, S) { | EntryY(R, S) { | | P(S); | V(S); | | V(R); | P(R); | | } | } | +---------------+----------------+ `

where `P()`

is a wait operation and `V()`

is a signal operation.

My doubt is will it make difference if we swap these operations, some like below?

`+---------------+----------------+ | ExitX(R, S) { | EntryY(R, S) { | | V(R); | P(R); | | P(S); | V(S); | | } | } | +---------------+----------------+ `

I believe there is no difference in the behavior and overall outcome of the code when either of above two solutions is used. Am I right?