From d304043c923d2e518c29cf7c5a7a334f2e35874e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Wed, 29 Dec 2021 18:24:21 +0100 Subject: [PATCH] feat: mutiple managers ? --- src/main/java/linda/search/basic/Main.java | 17 +++++++++++------ src/main/java/linda/search/basic/Manager.java | 1 - src/main/java/linda/search/basic/Searcher.java | 3 --- src/main/java/linda/shm/CentralizedLinda.java | 6 ++++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/linda/search/basic/Main.java b/src/main/java/linda/search/basic/Main.java index 94af623..b05cc24 100644 --- a/src/main/java/linda/search/basic/Main.java +++ b/src/main/java/linda/search/basic/Main.java @@ -4,24 +4,29 @@ import linda.*; public class Main { - private static final int NB_MANAGER = 1; private static final int NB_SEARCHER = 10; - public static void main(String args[]) { + public static void main(String args[]) throws InterruptedException { // if (args.length != 2) { // System.err.println("linda.search.basic.Main search file."); // return; // } Linda linda = new linda.shm.CentralizedLinda(); - for (int i = 0; i < NB_MANAGER; i++) { - Manager manager = new Manager(linda, "/usr/share/dict/french", "agneau"); - (new Thread(manager)).start(); - } + Manager manager1 = new Manager(linda, "/usr/share/dict/french", "abasourdir"); + Thread thread1 = new Thread(manager1); + thread1.start(); + + Manager manager2 = new Manager(linda, "/usr/share/dict/french", "agneau"); + Thread thread2 = new Thread(manager2); + thread2.start(); for (int i = 0; i < NB_SEARCHER; i++) { Searcher searcher = new Searcher(linda); (new Thread(searcher)).start(); } + + thread1.join(); + thread2.join(); } } diff --git a/src/main/java/linda/search/basic/Manager.java b/src/main/java/linda/search/basic/Manager.java index 358400b..f61511c 100644 --- a/src/main/java/linda/search/basic/Manager.java +++ b/src/main/java/linda/search/basic/Manager.java @@ -64,7 +64,6 @@ public class Manager implements Runnable { bestvalue = v; bestresult = s; System.out.println("New best (" + bestvalue + "): \"" + bestresult + "\""); - System.out.flush(); } // Tant qu'il reste des mots à chercher, ou des résultats à traiter diff --git a/src/main/java/linda/search/basic/Searcher.java b/src/main/java/linda/search/basic/Searcher.java index cdaf054..c42bdd3 100644 --- a/src/main/java/linda/search/basic/Searcher.java +++ b/src/main/java/linda/search/basic/Searcher.java @@ -17,7 +17,6 @@ public class Searcher implements Runnable { UUID reqUUID = (UUID) treq.get(1); String req = (String) treq.get(2); System.out.println("Looking for: " + req); - System.out.flush(); Tuple tv; while ((tv = linda.tryTake(new Tuple(Code.Value, String.class, reqUUID))) != null) { @@ -29,7 +28,6 @@ public class Searcher implements Runnable { } System.out.println("Ending search: " + req); - System.out.flush(); Tuple end = new Tuple(Code.Searcher, "done", reqUUID); if (linda.tryRead(end) == null) @@ -38,7 +36,6 @@ public class Searcher implements Runnable { public void run() { System.out.println("Ready to search"); - System.out.flush(); linda.read(new Tuple(Code.Request, UUID.class, String.class)); Collection treqs = linda.readAll(new Tuple(Code.Request, UUID.class, String.class)); diff --git a/src/main/java/linda/shm/CentralizedLinda.java b/src/main/java/linda/shm/CentralizedLinda.java index 78eae3b..ec3df7d 100644 --- a/src/main/java/linda/shm/CentralizedLinda.java +++ b/src/main/java/linda/shm/CentralizedLinda.java @@ -244,8 +244,10 @@ public class CentralizedLinda implements Linda { return; case FUTURE: Collection knownTuples = new ArrayList(); - for (Tuple t : tuples) { - knownTuples.add((Tuple) t.clone()); + synchronized (tuples) { + for (Tuple t : tuples) { + knownTuples.add((Tuple) t.clone()); + } } callback.call(future_search(template, knownTuples, mode)); return;