Semaphore execution when has 4 processes : Can any one please explain this for me??


 
 2. In the following code, four processes produce output using the routine “printf” and synchronize using three semaphores “R”, “S” and “T.” We assume ‘printf’ won’t cause context switch. 
 Semaphore R=1, S = 3, T = 0; /* initialization */ 
 /* process 1 */  /* process 2 */   /* process 3 */ /*process 4 */ while(true) {   while(true) {    while(true) {  while(true) {     P(S);             P(T);        P(T);     P(R);     printf(‘A’);           printf (‘B’);          printf (‘D’);       printf (‘E’);            printf (‘C’);            V(R);     V(T);       V(T);   }   } }    }        How many A and B’s are printed when this set of processes runs? A


Thanks