feat: mutiple managers ?

This commit is contained in:
Laureηt 2021-12-29 18:24:21 +01:00
parent e17c272636
commit d304043c92
No known key found for this signature in database
GPG key ID: D88C6B294FD40994
4 changed files with 15 additions and 12 deletions

View file

@ -4,24 +4,29 @@ import linda.*;
public class Main { public class Main {
private static final int NB_MANAGER = 1;
private static final int NB_SEARCHER = 10; 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) { // if (args.length != 2) {
// System.err.println("linda.search.basic.Main search file."); // System.err.println("linda.search.basic.Main search file.");
// return; // return;
// } // }
Linda linda = new linda.shm.CentralizedLinda(); Linda linda = new linda.shm.CentralizedLinda();
for (int i = 0; i < NB_MANAGER; i++) { Manager manager1 = new Manager(linda, "/usr/share/dict/french", "abasourdir");
Manager manager = new Manager(linda, "/usr/share/dict/french", "agneau"); Thread thread1 = new Thread(manager1);
(new Thread(manager)).start(); 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++) { for (int i = 0; i < NB_SEARCHER; i++) {
Searcher searcher = new Searcher(linda); Searcher searcher = new Searcher(linda);
(new Thread(searcher)).start(); (new Thread(searcher)).start();
} }
thread1.join();
thread2.join();
} }
} }

View file

@ -64,7 +64,6 @@ public class Manager implements Runnable {
bestvalue = v; bestvalue = v;
bestresult = s; bestresult = s;
System.out.println("New best (" + bestvalue + "): \"" + bestresult + "\""); System.out.println("New best (" + bestvalue + "): \"" + bestresult + "\"");
System.out.flush();
} }
// Tant qu'il reste des mots à chercher, ou des résultats à traiter // Tant qu'il reste des mots à chercher, ou des résultats à traiter

View file

@ -17,7 +17,6 @@ public class Searcher implements Runnable {
UUID reqUUID = (UUID) treq.get(1); UUID reqUUID = (UUID) treq.get(1);
String req = (String) treq.get(2); String req = (String) treq.get(2);
System.out.println("Looking for: " + req); System.out.println("Looking for: " + req);
System.out.flush();
Tuple tv; Tuple tv;
while ((tv = linda.tryTake(new Tuple(Code.Value, String.class, reqUUID))) != null) { 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.println("Ending search: " + req);
System.out.flush();
Tuple end = new Tuple(Code.Searcher, "done", reqUUID); Tuple end = new Tuple(Code.Searcher, "done", reqUUID);
if (linda.tryRead(end) == null) if (linda.tryRead(end) == null)
@ -38,7 +36,6 @@ public class Searcher implements Runnable {
public void run() { public void run() {
System.out.println("Ready to search"); System.out.println("Ready to search");
System.out.flush();
linda.read(new Tuple(Code.Request, UUID.class, String.class)); linda.read(new Tuple(Code.Request, UUID.class, String.class));
Collection<Tuple> treqs = linda.readAll(new Tuple(Code.Request, UUID.class, String.class)); Collection<Tuple> treqs = linda.readAll(new Tuple(Code.Request, UUID.class, String.class));

View file

@ -244,9 +244,11 @@ public class CentralizedLinda implements Linda {
return; return;
case FUTURE: case FUTURE:
Collection<Tuple> knownTuples = new ArrayList<Tuple>(); Collection<Tuple> knownTuples = new ArrayList<Tuple>();
synchronized (tuples) {
for (Tuple t : tuples) { for (Tuple t : tuples) {
knownTuples.add((Tuple) t.clone()); knownTuples.add((Tuple) t.clone());
} }
}
callback.call(future_search(template, knownTuples, mode)); callback.call(future_search(template, knownTuples, mode));
return; return;
} }