Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/26/12 15:49:52 (12 years ago)
Author:
mkommend
Message:

#1878: Added lock statement in Experiment.optimizer_Stopped to avoid a race condition.

File:
1 edited

Legend:

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

    r7797 r8129  
    180180      foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState != ExecutionState.Started))
    181181        //if (clearRuns || optimizer.ExecutionState != ExecutionState.Prepared)
    182           optimizer.Prepare(clearRuns);
     182        optimizer.Prepare(clearRuns);
    183183    }
    184184    public void Start() {
     
    341341      if (ExecutionState != ExecutionState.Started) OnStarted();
    342342    }
     343
     344    private object locker;
    343345    private void optimizer_Stopped(object sender, EventArgs e) {
    344       if (experimentStopped) {
    345         if (Optimizers.All(x => (x.ExecutionState == ExecutionState.Stopped) || (x.ExecutionState == ExecutionState.Prepared))) OnStopped();
    346       } else {
    347         if (experimentStarted && Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused))) {
    348           Optimizers.First(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)).Start();
    349         } else if (Optimizers.All(x => x.ExecutionState == ExecutionState.Stopped)) OnStopped();
    350         else if (Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)) && Optimizers.All(o => o.ExecutionState != ExecutionState.Started)) OnPaused();
     346      lock (locker) {
     347        if (experimentStopped) {
     348          if (Optimizers.All(x => (x.ExecutionState == ExecutionState.Stopped) || (x.ExecutionState == ExecutionState.Prepared))) OnStopped();
     349        } else {
     350          if (experimentStarted && Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused))) {
     351            Optimizers.First(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)).Start();
     352          } else if (Optimizers.All(x => x.ExecutionState == ExecutionState.Stopped)) OnStopped();
     353          else if (Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)) && Optimizers.All(o => o.ExecutionState != ExecutionState.Started)) OnPaused();
     354        }
    351355      }
    352356    }
Note: See TracChangeset for help on using the changeset viewer.