Line 6 to 10 must be kept inside the CS.

Suppose it wasn't kept then,

P(S);
process_arrived++;
V(S);
while (process_arrived !=3);
process_left++;
if (process_left==3) {
process_arrived = 0;
process_left = 0;
}

Now let P1 executes process_left++; This is not an atomic operation. We know how it is implemented in machine language.

L1:reg1=process_left;
L2:reg1=reg1+1;
L3:process_left=reg1;

Suppose P1 preempts after L2.So reg1=1 and process_left remains 0 as reg1 is not stored back into it.

P2 executes process_left++ in the similar way and pre empts at L2 so reg2=1 and process_left=0.

Then P3 does the same thing and pre empts at L2 so reg3=1 and process_left=0.

Now again let P1 gets back control at L3 and process_left=reg1=1.

Similarly P2 executes L3 and process_left=reg2=1 and same does the P3 do so again process_left=reg3=1.

So now if(process_left==3) is never satisfied and process_arrived value remains 3 and process_left=1.

Let these processes again invoke Barrier, all of them will get stuck at

while(process_arrived!=3);as the process_arrived will be greater than 3 now. Hence Deadlock. So it is necessary to put the block from Line 6 to 10 inside CS so that this does not happen.