From: Jérôme Benoit Date: Fri, 9 Mar 2018 20:56:06 +0000 (+0100) Subject: Switch CRLF to LF line endings. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=18eb400ba6dc197a9be104038fa60055bcd83813;p=TD_SR.git Switch CRLF to LF line endings. Signed-off-by: Jérôme Benoit --- diff --git a/TD1/exo3/BufferCirc.java b/TD1/exo3/BufferCirc.java index ebfb287..4571085 100644 --- a/TD1/exo3/BufferCirc.java +++ b/TD1/exo3/BufferCirc.java @@ -1,68 +1,68 @@ - - -/** - * implementation du producteur consommateur avec un buffer circulaire - */ -public class BufferCirc { - - private Object[] tampon; - private int taille; - private int prem, der, nbObj; - - - public BufferCirc (int t) { - taille = t; - tampon = new Object[taille]; - prem = 0; - der = 0; - nbObj = 0; - } - - - public boolean isEmpty() { - return nbObj == 0; - } - - - public boolean isFull() { - return nbObj == taille; - } - - - public synchronized void depose(Object obj) { - while(isFull()) { - try { - System.out.println("Buffer is full: " + Thread.currentThread().getName() - + " is waiting, size: " + nbObj); - - wait(); - } - catch (InterruptedException e) {} - } - nbObj++; - tampon[prem] = obj; - prem = (prem + 1) % taille; - //System.out.println(Thread.currentThread().getName() + " a depose " + (Integer)obj); - notifyAll(); - } - - - public synchronized Object preleve() { - while(isEmpty()) { - try { - System.out.println("Buffer is empty: " + Thread.currentThread().getName() - + " is waiting, size: " + nbObj); - wait(); - } - catch (InterruptedException e) {} - } - Object outObj = null; - nbObj--; - outObj = tampon[der]; - der = (der + 1) % taille; - //System.out.println(Thread.currentThread().getName() + " a preleve " + (Integer)outObj); - notifyAll(); - return outObj; - } - -} // fin class BufferCirc + + +/** + * implementation du producteur consommateur avec un buffer circulaire + */ +public class BufferCirc { + + private Object[] tampon; + private int taille; + private int prem, der, nbObj; + + + public BufferCirc (int t) { + taille = t; + tampon = new Object[taille]; + prem = 0; + der = 0; + nbObj = 0; + } + + + public boolean isEmpty() { + return nbObj == 0; + } + + + public boolean isFull() { + return nbObj == taille; + } + + + public synchronized void depose(Object obj) { + while(isFull()) { + try { + System.out.println("Buffer is full: " + Thread.currentThread().getName() + + " is waiting, size: " + nbObj); + + wait(); + } + catch (InterruptedException e) {} + } + nbObj++; + tampon[prem] = obj; + prem = (prem + 1) % taille; + //System.out.println(Thread.currentThread().getName() + " a depose " + (Integer)obj); + notifyAll(); + } + + + public synchronized Object preleve() { + while(isEmpty()) { + try { + System.out.println("Buffer is empty: " + Thread.currentThread().getName() + + " is waiting, size: " + nbObj); + wait(); + } + catch (InterruptedException e) {} + } + Object outObj = null; + nbObj--; + outObj = tampon[der]; + der = (der + 1) % taille; + //System.out.println(Thread.currentThread().getName() + " a preleve " + (Integer)outObj); + notifyAll(); + return outObj; + } + +} // fin class BufferCirc diff --git a/TD1/exo3/Consommateur.java b/TD1/exo3/Consommateur.java index 28a5efa..4801349 100644 --- a/TD1/exo3/Consommateur.java +++ b/TD1/exo3/Consommateur.java @@ -1,33 +1,33 @@ -import java.util.concurrent.ThreadLocalRandom; - - -public class Consommateur implements Runnable { - - private BufferCirc buffer; - - public Consommateur(BufferCirc b) { - buffer = b; - } - - public Consommateur(BufferCirc b, String name) { - buffer = b; - setThName(name); - } - - public void setThName(String name) { - Thread.currentThread().setName(name); - } - - public void run() { - Integer val; - while (true) { - val = (Integer)buffer.preleve(); - System.out.println (Thread.currentThread().getName() + " a preleve " + val); - try { - Thread.sleep(ThreadLocalRandom.current().nextInt(1001)); - } - catch (InterruptedException e) {} - } - } - -} // fin classe Consommateur +import java.util.concurrent.ThreadLocalRandom; + + +public class Consommateur implements Runnable { + + private BufferCirc buffer; + + public Consommateur(BufferCirc b) { + buffer = b; + } + + public Consommateur(BufferCirc b, String name) { + buffer = b; + setThName(name); + } + + public void setThName(String name) { + Thread.currentThread().setName(name); + } + + public void run() { + Integer val; + while (true) { + val = (Integer)buffer.preleve(); + System.out.println (Thread.currentThread().getName() + " a preleve " + val); + try { + Thread.sleep(ThreadLocalRandom.current().nextInt(1001)); + } + catch (InterruptedException e) {} + } + } + +} // fin classe Consommateur diff --git a/TD1/exo3/Main.java b/TD1/exo3/Main.java index 78c3b03..af0ba12 100644 --- a/TD1/exo3/Main.java +++ b/TD1/exo3/Main.java @@ -1,27 +1,27 @@ - -import java.util.ArrayList; - - -public class Main { - - - public static void main (String[] args) { - final int BUFFER_SIZE = 1; - final int PROD_NUMBER = 20; - final int CONS_NUMBER = 20; - BufferCirc b = new BufferCirc(BUFFER_SIZE); - Thread[] P = new Thread[PROD_NUMBER]; - Thread[] C = new Thread[CONS_NUMBER]; - for (int i = 0; i < P.length; i++) { - P[i] = new Thread(new Producteur(b)); - P[i].setName("P" + i); - P[i].start(); - } - for (int i = 0; i < C.length; i++) { - C[i] = new Thread(new Consommateur(b)); - C[i].setName("C" + i); - C[i].start(); - } - } - -} + +import java.util.ArrayList; + + +public class Main { + + + public static void main (String[] args) { + final int BUFFER_SIZE = 1; + final int PROD_NUMBER = 20; + final int CONS_NUMBER = 20; + BufferCirc b = new BufferCirc(BUFFER_SIZE); + Thread[] P = new Thread[PROD_NUMBER]; + Thread[] C = new Thread[CONS_NUMBER]; + for (int i = 0; i < P.length; i++) { + P[i] = new Thread(new Producteur(b)); + P[i].setName("P" + i); + P[i].start(); + } + for (int i = 0; i < C.length; i++) { + C[i] = new Thread(new Consommateur(b)); + C[i].setName("C" + i); + C[i].start(); + } + } + +} diff --git a/TD1/exo3/Producteur.java b/TD1/exo3/Producteur.java index f7f3c47..47a4021 100644 --- a/TD1/exo3/Producteur.java +++ b/TD1/exo3/Producteur.java @@ -1,35 +1,35 @@ -import java.util.concurrent.ThreadLocalRandom; - - -public class Producteur implements Runnable { - - private BufferCirc buffer; - private int val; - - - public Producteur(BufferCirc b) { - buffer = b; - } - - public Producteur(BufferCirc b, String name) { - buffer = b; - setThName(name); - } - - public void setThName(String name) { - Thread.currentThread().setName(name); - } - - public void run() { - while (true) { - buffer.depose(new Integer(val)); - System.out.println (Thread.currentThread().getName() + " a depose " + val); - val++; - try { - Thread.sleep(ThreadLocalRandom.current().nextInt(101)); - } - catch (InterruptedException e) {} - } - } - -} // fin classe Producteur +import java.util.concurrent.ThreadLocalRandom; + + +public class Producteur implements Runnable { + + private BufferCirc buffer; + private int val; + + + public Producteur(BufferCirc b) { + buffer = b; + } + + public Producteur(BufferCirc b, String name) { + buffer = b; + setThName(name); + } + + public void setThName(String name) { + Thread.currentThread().setName(name); + } + + public void run() { + while (true) { + buffer.depose(new Integer(val)); + System.out.println (Thread.currentThread().getName() + " a depose " + val); + val++; + try { + Thread.sleep(ThreadLocalRandom.current().nextInt(101)); + } + catch (InterruptedException e) {} + } + } + +} // fin classe Producteur diff --git a/TD2/Main.java b/TD2/Main.java index 9e4fba5..822fb58 100644 --- a/TD2/Main.java +++ b/TD2/Main.java @@ -1,19 +1,19 @@ -import java.io.*; - - -public class Main { - - - public static void main (String[] args) { - - ClientSimplifie client = new ClientSimplifie(); - - client.sendMsg("Line 1 Line 2"); - String msg = client.receiveMsg(); - System.out.println(msg); - - client.closeRWIO(); - - } - -} +import java.io.*; + + +public class Main { + + + public static void main (String[] args) { + + ClientSimplifie client = new ClientSimplifie(); + + client.sendMsg("Line 1 Line 2"); + String msg = client.receiveMsg(); + System.out.println(msg); + + client.closeRWIO(); + + } + +}