Ignore:
Timestamp:
Nov 20, 2010, 2:16:16 PM (11 years ago)
Author:
Sven Rech
Message:

some p2p keysearcher changes (all related to better disconnect handling)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/KeySearcher/KeySearcher.cs

    r2114 r2115  
    5555        private int maxThread;
    5656        private readonly Mutex maxThreadMutex = new Mutex();
     57        private ArrayList threadsStopEvents;
    5758
    5859        public bool IsKeySearcherRunning;
     
    359360        private void KeySearcherJob(object param)
    360361        {
     362            AutoResetEvent stopEvent = new AutoResetEvent(false);
     363            threadsStopEvents.Add(stopEvent);
     364
    361365            object[] parameters = (object[])param;
    362366            KeyPattern.KeyPattern[] patterns = (KeyPattern.KeyPattern[])parameters[0];
     
    426430            {
    427431                sender.Dispose();
     432                stopEvent.Set();
    428433            }
    429434        }
     
    438443                int deviceIndex = settings.OpenCLDevice;
    439444               
    440                 Mem costs = oclManager.Context.CreateBuffer(MemFlags.READ_ONLY, costArray.Length * 4);
     445                Mem costs = oclManager.Context.CreateBuffer(MemFlags.READ_WRITE, costArray.Length * 4);
    441446                IntPtr[] globalWorkSize = { (IntPtr)keyTranslator.GetOpenCLBatchSize() };
    442447
     
    707712            BigInteger[] keysleft = new BigInteger[patterns.Length];
    708713            Stack threadStack = Stack.Synchronized(new Stack());
     714            threadsStopEvents = ArrayList.Synchronized(new ArrayList());
    709715            StartThreads(sender, bytesToUse, patterns, doneKeysA, keycounters, keysleft, threadStack);
    710716
     
    780786            while (threadStack.Count != 0)
    781787                ((ThreadStackElement)threadStack.Pop()).ev.Set();
     788
     789            //wait until all threads finished:
     790            foreach (AutoResetEvent stopEvent in threadsStopEvents)
     791            {
     792                stopEvent.WaitOne();
     793            }
    782794
    783795            if (!stop && !redirectResultsToStatisticsGenerator)
Note: See TracChangeset for help on using the changeset viewer.