Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. package ejercicios;
  2.  
  3. import static es.urjc.etsii.code.concurrency.SimpleConcurrent.*;
  4.  
  5. import es.urjc.etsii.code.concurrency.SimpleSemaphore;
  6.  
  7. public class Ejer14 {
  8.  
  9.     static SimpleSemaphore semSinc;
  10.     static SimpleSemaphore semN;
  11.     static final int N_PROC = 4;
  12.    
  13.     public static void proc()
  14.     {
  15.         System.out.print("A");
  16.    
  17.         semN.release();
  18.            
  19.         if(semN.permits() < N_PROC)
  20.         {
  21.             semSinc.acquire();
  22.         }
  23.         else
  24.         {
  25.             semSinc.release(N_PROC-1);
  26.         }
  27.            
  28.         System.out.print("B");
  29.     }
  30.    
  31.     public static void main(String[] args) {
  32.         semSinc = new SimpleSemaphore(0);
  33.         semN = new SimpleSemaphore(0);
  34.         createThreads(N_PROC,"proc");
  35.         startThreadsAndWait();
  36.        
  37.     }
  38.    
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement