Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/14/15 14:28:38 (9 years ago)
Author:
gkronber
Message:

#2061: fixed a contention problem when updating the execution time of an experiment with many concurrent optimizers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/crossvalidation-2434/HeuristicLab.Optimization/3.3/MetaOptimizers/Experiment.cs

    r12504 r12949  
    2424using System.Drawing;
    2525using System.Linq;
     26using System.Threading;
    2627using HeuristicLab.Collections;
    2728using HeuristicLab.Common;
     
    345346
    346347    private readonly object locker = new object();
     348    private readonly object runsLocker = new object();
    347349    private void optimizer_ExceptionOccurred(object sender, EventArgs<Exception> e) {
    348350      lock (locker)
     
    350352    }
    351353    private void optimizer_ExecutionTimeChanged(object sender, EventArgs e) {
    352       lock (locker)
    353         ExecutionTime = Optimizers.Aggregate(TimeSpan.Zero, (t, o) => t + o.ExecutionTime);
     354      // only wait for maximally 100ms to acquire lock, otherwise return and don't update the execution time
     355      var success = Monitor.TryEnter(locker, 100);
     356      if (!success) return;
     357      ExecutionTime = Optimizers.Aggregate(TimeSpan.Zero, (t, o) => t + o.ExecutionTime);
     358      Monitor.Exit(locker);
    354359    }
    355360    private void optimizer_Paused(object sender, EventArgs e) {
     
    378383    }
    379384    private void optimizer_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    380       lock (locker) {
     385      lock (runsLocker) {
    381386        Runs.RemoveRange(e.OldItems);
    382387        Runs.AddRange(e.Items);
     
    384389    }
    385390    private void optimizer_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    386       lock (locker)
     391      lock (runsLocker)
    387392        Runs.AddRange(e.Items);
    388393    }
    389394    private void optimizer_Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    390       lock (locker)
     395      lock (runsLocker)
    391396        Runs.RemoveRange(e.Items);
    392397    }
Note: See TracChangeset for help on using the changeset viewer.