Exemple #1
0
 /// <summary> Waits until the solver ends the execution.</summary>
 public virtual void Join()
 {
     lock (this)
     {
         if (debug)
         {
             Console.Out.WriteLine(name + " Join");
         }
         while (thread == null)
         {
             try
             {
                 System.Threading.Monitor.Wait(this);
             }
             catch (System.Threading.ThreadInterruptedException)
             {
             }
         }
         while (running)
         {
             try
             {
                 System.Threading.Monitor.Wait(this);
             }
             catch (System.Threading.ThreadInterruptedException)
             {
             }
         }
         thread = null;
     }
 }
Exemple #2
0
 /// <summary> Starts the solver in a new thread with the timeout, and immediately returns to the caller.
 /// When the <tt>timeout</tt> milliseconds have been elapsed
 /// since the Start of the solver, it stops the execution.
 /// The {@link #WaitNext()} and {@link #WaitNext(long timeout)} methods can be used
 /// to wait the next solution, or to detect the timeout.
 /// When a solution is found, the solver suspends the execution until
 /// the {@link #Resume()} method is called.
 /// You can Stop the solver anytime by calling the {@link #Stop()} method.
 /// </summary>
 /// <param name="timeout">timeout in milliseconds (non-positive value means no timeout)
 /// </param>
 public virtual void Start(long timeout)
 {
     lock (this)
     {
         // For bug fix. (ParallelSolver would not Stop)
         // Modified by Muneyuki Kawatani 05/12/09
         thread = null;
         if (debug)
         {
             Console.Out.WriteLine(name + " Start");
         }
         startTime    = (DateTime.Now.Ticks - 621355968000000000) / 10000;
         totalTimeout = timeout;
         abort        = false;
         running      = true;
         ready        = false;
         solution     = null;
         thread       = new SupportClass.ThreadClass(new System.Threading.ThreadStart(Run));
         thread.Start();
         System.Threading.Monitor.PulseAll(this);
     }
 }
Exemple #3
0
 /// <summary> Starts the solver in a new thread with the timeout, and immediately returns to the caller.
 /// When the <tt>timeout</tt> milliseconds have been elapsed
 /// since the Start of the solver, it stops the execution.
 /// The {@link #WaitNext()} and {@link #WaitNext(long timeout)} methods can be used
 /// to wait the next solution, or to detect the timeout.
 /// When a solution is found, the solver suspends the execution until
 /// the {@link #Resume()} method is called.
 /// You can Stop the solver anytime by calling the {@link #Stop()} method.
 /// </summary>
 /// <param name="timeout">timeout in milliseconds (non-positive value means no timeout)
 /// </param>
 public virtual void Start(long timeout)
 {
     lock (this)
     {
         // For bug fix. (ParallelSolver would not Stop)
         // Modified by Muneyuki Kawatani 05/12/09
         _thread = null;
         if (debug)
         {
             Console.Out.WriteLine(name + " Start");
         }
         startTime = (DateTime.Now.Ticks - 621355968000000000) / 10000;
         totalTimeout = timeout;
         _abort = false;
         _running = true;
         _ready = false;
         solution = null;
         _thread = new SupportClass.ThreadClass(new System.Threading.ThreadStart(Run));
         _thread.Start();
         System.Threading.Monitor.PulseAll(this);
     }
 }
Exemple #4
0
 /// <summary> Waits until the solver ends the execution.</summary>
 public virtual void Join()
 {
     lock (this)
     {
         if (debug)
         {
             Console.Out.WriteLine(name + " Join");
         }
         while (_thread == null)
         {
             try
             {
                 System.Threading.Monitor.Wait(this);
             }
             catch (System.Threading.ThreadInterruptedException)
             {
             }
         }
         while (_running)
         {
             try
             {
                 System.Threading.Monitor.Wait(this);
             }
             catch (System.Threading.ThreadInterruptedException)
             {
             }
         }
         _thread = null;
     }
 }