Changeset 8776


Ignore:
Timestamp:
10/10/12 12:01:52 (7 years ago)
Author:
svonolfe
Message:

Improved interaction of simulation and optimization thread (#1955)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DynamicVehicleRouting/HeuristicLab.PDPSimulation/3.3/PickupDeliveryOptimization.cs

    r8773 r8776  
    331331    CancellationTokenSource cts;
    332332
    333     private object threadLocker = new object();
    334333    protected bool running;
    335334
    336335    public void Start(bool synchronized) {
    337336      running = true;
    338       started = false;
    339337      InitWaitHandle(synchronized);
     338
     339      EventWaitHandle wh = new EventWaitHandle(false, EventResetMode.ManualReset);
    340340
    341341      cts = new CancellationTokenSource();
    342342      optThread = new Thread(delegate() {
    343         lock (threadLocker) {
    344           started = true;
    345         }
     343        wh.Set();
    346344        Optimize(cts.Token);
    347345      });
     
    349347      optThread.Start();
    350348
    351       while (!Started())
    352         Thread.Sleep(100);
     349      wh.WaitOne();
    353350    }
    354351
     
    364361    }
    365362
    366     private bool started;
    367     private bool Started() {
    368       bool result;
    369       lock (threadLocker) {
    370         result = started;
    371         started = false;
    372       }
    373       return result;
    374     }
    375 
    376363    public bool Running() {
    377364      return optThread != null && optThread.IsAlive && running;
     
    381368      while (Running()) {
    382369        Thread.Sleep(100);
     370        SignalWaitHandle();
    383371      }
    384372      optThread = null;
Note: See TracChangeset for help on using the changeset viewer.