Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6188


Ignore:
Timestamp:
05/12/11 15:38:45 (12 years ago)
Author:
epitzer
Message:

improve synchronization of cache (#1516)

  • set locks per instance instead of static
  • remove failed evaluations from active set
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/EvaluationCache.cs

    r6183 r6188  
    7474    private LinkedList<CacheEntry> list;
    7575    private Dictionary<CacheEntry, LinkedListNode<CacheEntry>> index;
    76     private static HashSet<string> activeEvaluations = new HashSet<string>();
    77     private static object cacheLock = new object();
    78     private static object evaluationLock = new object();
    79     private static AutoResetEvent evaluationDone = new AutoResetEvent(false);
     76    private HashSet<string> activeEvaluations = new HashSet<string>();
     77    private object cacheLock = new object();
     78    private object evaluationLock = new object();
     79    private AutoResetEvent evaluationDone = new AutoResetEvent(false);
    8080    #endregion
    8181
     
    250250          Monitor.Exit(evaluationLock);
    251251          OnActiveEvalutionsChanged();
    252           entry.Value = evaluate(message);
    253           lock (cacheLock) {
    254             index[entry] = list.AddLast(entry);
     252          try {
     253            entry.Value = evaluate(message);
     254            lock (cacheLock) {
     255              index[entry] = list.AddLast(entry);
     256            }
     257            Trim();
     258          } finally {
     259            lock (evaluationLock) {
     260              activeEvaluations.Remove(entry.Key);
     261              evaluationDone.Set();
     262            }
     263            OnActiveEvalutionsChanged();
    255264          }
    256           lock (evaluationLock) {
    257             activeEvaluations.Remove(entry.Key);
    258             evaluationDone.Set();
    259           }
    260           OnActiveEvalutionsChanged();
    261           Trim();
    262265          return entry.Value;
    263266        }
Note: See TracChangeset for help on using the changeset viewer.