From 0f6799fa421fe8f3dd9341711a264b37171fbf29 Mon Sep 17 00:00:00 2001 From: michelefiori Date: Sun, 7 Apr 2024 17:13:22 +0200 Subject: [PATCH] Switched comments to english --- .DS_Store | Bin 6148 -> 6148 bytes .idea/compiler.xml | 2 +- .idea/misc.xml | 2 +- src/main/java/join/Main.java | 6 +++--- src/main/java/semaphore/Main.java | 4 ++-- src/main/java/semaphore/MyThread.java | 2 +- src/main/java/semaphore/Semaphore.java | 12 ++++++------ 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.DS_Store b/.DS_Store index a9c42ff4dba4e7e5df43e20a23bc5a0897baa943..85518c22e9915c664387292c1ff657ead931ec66 100644 GIT binary patch delta 32 ocmZoMXfc@J&&azmU^g=(?`9sB+l-r~+1@ZtY%tl(&heKY0IN?5mH+?% delta 67 zcmZoMXfc@J&&aniU^g=(-)0_`+l;DQ3_%R842}#g48B0RjzNzhmm$S7CqFqUCqIdS WfkA+Qfl+qz4c6a`o7p-3@&f=baS+S^ diff --git a/.idea/compiler.xml b/.idea/compiler.xml index fb7f4a8..b73660a 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index be6c998..bf3cfc9 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/src/main/java/join/Main.java b/src/main/java/join/Main.java index fedf709..26e497c 100644 --- a/src/main/java/join/Main.java +++ b/src/main/java/join/Main.java @@ -9,19 +9,19 @@ public class Main { public static void main(String arg[]) throws Exception { Random r = new Random(); ArrayList threads = new ArrayList(); - //create some threads + //Create some threads for (int i=0; i<10; i++) { MyThread mt = new MyThread(r); threads.add(mt); } System.out.println("All threads have been created."); - //start all the threads + //Start all the threads for (Thread t: threads) { t.start(); } System.out.println("All threads have been started."); System.out.println("Start waiting for all thread to finish..."); - //wait all the thread to finish + //Wait all the thread to finish for (Thread t : threads) { t.join(); } diff --git a/src/main/java/semaphore/Main.java b/src/main/java/semaphore/Main.java index 1315fcb..73e6751 100644 --- a/src/main/java/semaphore/Main.java +++ b/src/main/java/semaphore/Main.java @@ -8,13 +8,13 @@ public class Main { Random r = new Random(); ArrayList threads = new ArrayList(); Semaphore s = new Semaphore(4); - //create some threads + //Create some threads for (int i=0; i<10; i++) { MyThread mt = new MyThread(r, i, s); threads.add(mt); } - //start all the threads + //Start all the threads for (Thread t: threads) { t.start(); } diff --git a/src/main/java/semaphore/MyThread.java b/src/main/java/semaphore/MyThread.java index b15b661..bb3202e 100644 --- a/src/main/java/semaphore/MyThread.java +++ b/src/main/java/semaphore/MyThread.java @@ -18,7 +18,7 @@ public class MyThread extends Thread { System.out.println("Thread " + id + " wants to enter in the critical region"); sem.enter(); System.out.println("Thread " + id + " entered in the critical region!"); - wasteSomeTime(); //it takes some times to compleate the work in the critical region + wasteSomeTime(); //It takes some times to compleate the work in the critical region System.out.println("Thread " + id + " is going to get out from the critical region"); sem.exit(); }//end run diff --git a/src/main/java/semaphore/Semaphore.java b/src/main/java/semaphore/Semaphore.java index f075e31..1fe4ff5 100644 --- a/src/main/java/semaphore/Semaphore.java +++ b/src/main/java/semaphore/Semaphore.java @@ -1,9 +1,9 @@ -package semaphore;//Classe che implementa tramite wait e notify un Semaforo. -//Se non vi ricordate cosa sia un semaforo, google is your best friend. +package semaphore;//Class that implements a semaphore, thanks to wait() and notify() +//If you need to recap what a semaphore is, Google is your best friend. public class Semaphore { - private int maxNumber; //numero massimo di thread - private int threadsIn; //conteggio dei thread nell'area critica + private int maxNumber; //Maximum number of threads + private int threadsIn; //Number of threads in the critical region Semaphore(int max) { maxNumber = max; @@ -12,7 +12,7 @@ public class Semaphore { public synchronized void enter() { System.out.println("" + threadsIn + " in the critical region..."); - //quando abbiamo raggiunto il numero massimo di thread, chi vuole entrare aspetta + //When we reach the maximum number of threads, new threads need to wait while (threadsIn >= maxNumber) { try {this.wait();} catch(InterruptedException ie) {ie.printStackTrace();} @@ -23,7 +23,7 @@ public class Semaphore { public synchronized void exit() { threadsIn--; - //quando un thread esce dall'area critica, sveglia qualcuno in attesa di entrare (se presente) + //Whena thread exits the critical region, it awakens another thread that is waiting (if there is one) this.notify(); } } -- 2.18.1