Line 6 to 10 must be kept inside the CS.
Suppose it wasn't kept then,
while (process_arrived !=3);
Now let P1 executes process_left++; This is not an atomic operation. We know how it is implemented in machine language.
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.