Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15327 for trunk/sources


Ignore:
Timestamp:
08/17/17 12:51:06 (7 years ago)
Author:
pfleck
Message:

#2823 Fixed potential early return of sync Start method.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization/3.3/MetaOptimizers/Experiment.cs

    r15287 r15327  
    111111    private bool experimentStarted = false;
    112112    private bool experimentStopped = false;
     113    private ManualResetEventSlim allOptimizerFinished; // this indicates that all started optimizers have been paused or stopped
    113114
    114115    public Experiment()
     
    195196      experimentStarted = true;
    196197      experimentStopped = false;
     198      allOptimizerFinished = new ManualResetEventSlim(false);
     199
    197200      IOptimizer optimizer;
    198201      while ((optimizer = Optimizers.FirstOrDefault(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused))) != null) {
     
    201204        if (ExecutionState == ExecutionState.Paused || ExecutionState == ExecutionState.Stopped) break;
    202205      }
     206
     207      allOptimizerFinished.Wait();
    203208    }
    204209    public async Task StartAsync() { await StartAsync(CancellationToken.None); }
     
    368373    private void optimizer_Paused(object sender, EventArgs e) {
    369374      lock (locker)
    370         if (Optimizers.All(x => x.ExecutionState != ExecutionState.Started)) OnPaused();
     375        if (Optimizers.All(x => x.ExecutionState != ExecutionState.Started)) {
     376          OnPaused();
     377          allOptimizerFinished.Set();
     378        }
    371379    }
    372380    private void optimizer_Prepared(object sender, EventArgs e) {
     
    381389      lock (locker) {
    382390        if (experimentStopped) {
    383           if (Optimizers.All(x => (x.ExecutionState == ExecutionState.Stopped) || (x.ExecutionState == ExecutionState.Prepared))) OnStopped();
     391          if (Optimizers.All(x => (x.ExecutionState == ExecutionState.Stopped) || (x.ExecutionState == ExecutionState.Prepared))) {
     392            OnStopped();
     393            allOptimizerFinished.Set();
     394          }
    384395        } else {
    385396          if (experimentStarted && Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused))) return;
    386           else if (Optimizers.All(x => x.ExecutionState == ExecutionState.Stopped)) OnStopped();
    387           else if (Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)) && Optimizers.All(o => o.ExecutionState != ExecutionState.Started)) OnPaused();
     397          else if (Optimizers.All(x => x.ExecutionState == ExecutionState.Stopped)) {
     398            OnStopped();
     399            allOptimizerFinished.Set();
     400          } else if (Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)) && Optimizers.All(o => o.ExecutionState != ExecutionState.Started)) {
     401            OnPaused();
     402            allOptimizerFinished.Set();
     403          }
    388404        }
    389405      }
Note: See TracChangeset for help on using the changeset viewer.