Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1033


Ignore:
Timestamp:
12/18/08 16:41:10 (16 years ago)
Author:
kgrading
Message:

added locking to avoid race conditions (#440)

Location:
trunk/sources/HeuristicLab.Hive.Client.Core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Client.Core/ClientConsoleService/ClientConsoleCommunicator.cs

    r959 r1033  
    1212
    1313    public StatusCommons GetStatusInfos() {
    14       return ConfigManager.Instance.GetStatusForClientConsole();
     14      lock (Core.Locker) {
     15        return ConfigManager.Instance.GetStatusForClientConsole();
     16      }
    1517    }
    1618
  • trunk/sources/HeuristicLab.Hive.Client.Core/Core.cs

    r1032 r1033  
    4949    public delegate string GetASnapshotDelegate();
    5050
     51    public static Object Locker { get; set; }
     52
    5153    Dictionary<long, Executor> engines = new Dictionary<long, Executor>();
    5254    Dictionary<long, AppDomain> appDomains = new Dictionary<long, AppDomain>();
     
    149151
    150152        PluginManager.Manager.Initialize();
    151         AppDomain appDomain =  PluginManager.Manager.CreateAndInitAppDomainWithSandbox(e.Result.Job.Id.ToString(), sandboxed, typeof(TestJob));
     153        AppDomain appDomain = PluginManager.Manager.CreateAndInitAppDomainWithSandbox(e.Result.Job.Id.ToString(), sandboxed, typeof(TestJob));
    152154        appDomain.UnhandledException += new UnhandledExceptionEventHandler(appDomain_UnhandledException);
    153         if (!jobs.ContainsKey(e.Result.Job.Id)) {
    154           jobs.Add(e.Result.Job.Id, e.Result.Job);
    155           appDomains.Add(e.Result.Job.Id, appDomain);
    156 
    157           Executor engine = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName);
    158           engine.JobId = e.Result.Job.Id;
    159           engine.Queue = MessageQueue.GetInstance();
    160           engine.Start(e.Result.SerializedJob);
    161           engines.Add(e.Result.Job.Id, engine);
    162 
    163           ClientStatusInfo.JobsFetched++;
    164 
    165           Debug.WriteLine("Increment FetchedJobs to:" + ClientStatusInfo.JobsFetched);
     155        lock (Locker) {
     156          if (!jobs.ContainsKey(e.Result.Job.Id)) {
     157            jobs.Add(e.Result.Job.Id, e.Result.Job);
     158            appDomains.Add(e.Result.Job.Id, appDomain);
     159
     160            Executor engine = (Executor)appDomain.CreateInstanceAndUnwrap(typeof(Executor).Assembly.GetName().Name, typeof(Executor).FullName);
     161            engine.JobId = e.Result.Job.Id;
     162            engine.Queue = MessageQueue.GetInstance();
     163            engine.Start(e.Result.SerializedJob);
     164            engines.Add(e.Result.Job.Id, engine);
     165
     166            ClientStatusInfo.JobsFetched++;
     167
     168            Debug.WriteLine("Increment FetchedJobs to:" + ClientStatusInfo.JobsFetched);
     169          }
    166170        }
    167171      }
     
    170174    void wcfService_SendJobResultCompleted(object sender, SendJobResultCompletedEventArgs e) {
    171175      if (e.Result.Success) {
    172         AppDomain.Unload(appDomains[e.Result.Job.Id]);
    173         appDomains.Remove(e.Result.Job.Id);
    174         engines.Remove(e.Result.Job.Id);
    175         jobs.Remove(e.Result.Job.Id);
    176         ClientStatusInfo.JobsProcessed++;
     176        lock (Locker) {
     177          AppDomain.Unload(appDomains[e.Result.Job.Id]);
     178          appDomains.Remove(e.Result.Job.Id);
     179          engines.Remove(e.Result.Job.Id);
     180          jobs.Remove(e.Result.Job.Id);
     181          ClientStatusInfo.JobsProcessed++;
     182        }
    177183        Debug.WriteLine("ProcessedJobs to:" + ClientStatusInfo.JobsProcessed);
    178184      } else {
Note: See TracChangeset for help on using the changeset viewer.