diff --git a/src/main.py b/src/main.py index 5ecf941..2bbe97b 100644 --- a/src/main.py +++ b/src/main.py @@ -30,7 +30,7 @@ PREEMPTION_GLOBAL_SPACE = [True] * SPACE_SIZE DRAWING_GLOBAL_SPACE = [] ARROW_LIST = [(random.randint(0,SPACE_SIZE - 1),0) for x in range(ARROW_NUMBER)] TRANSITIONS_TREE = None -MAX_THREAD = 10 +MAX_THREAD = 0 masterThread = scheduler.GreatScheduler(PREEMPTION_GLOBAL_SPACE, TRANSITIONS_TREE, ARROW_LIST, MAX_THREAD, MAX_CYCLES) @@ -38,4 +38,4 @@ masterThread.start() server.ServerCLI.start() ## Exiting -scheduler.masterThread = True \ No newline at end of file +masterThread.stopped = True diff --git a/src/scheduler.py b/src/scheduler.py index 491c624..eec255a 100644 --- a/src/scheduler.py +++ b/src/scheduler.py @@ -19,7 +19,7 @@ # along with this program. If not, see . # #=----------------------------------------------------------------------------=# -import multiprocessing, threading +import os, multiprocessing, threading import random import localthread @@ -34,10 +34,17 @@ class GreatScheduler(threading.Thread): self.preemption_space = preemption_space self.transition_tree = transitions_tree self.arrow_list = arrow_list - self.n_thread = n_thread + + if n_thread == 0: # No limit + # Use number of usable CPUs multiplied by 3 + self.n_thread = len(os.sched_getaffinity(0)) * 3 + else: + self.n_thread = n_thread + self.cur_id = -1 self.n_cycle = -1 self.nmax_cycles = nmax_cycles + self.stopped = False def run(self): @@ -99,4 +106,4 @@ class GreatScheduler(threading.Thread): print("A optimiser : créer une règle") else: raise thread.namespace.returncode - print("Thread local n°{} est terminé".format(thread.id)) \ No newline at end of file + print("Thread local n°{} est terminé".format(thread.id))