summaryrefslogtreecommitdiff
path: root/Analizator9000
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2014-12-20 18:49:46 +0000
committeremkael <emkael@tlen.pl>2014-12-20 18:49:46 +0000
commitbdb347debe455ef86e29f01a81bfcae4a7c5c16c (patch)
tree40e6ae1ebf8a7c86e91975c990dedd00b01ec2fb /Analizator9000
parent203260cab1c78f8761be8550ce6d781d0c0867f6 (diff)
* parallel code troubleshoot and bugfix
git-svn-id: https://svn.emkael.info/an9k@30 05ec0d5d-773b-4d93-9e23-c81a7ac79feb
Diffstat (limited to 'Analizator9000')
-rw-r--r--Analizator9000/Analizator9000/Accumulator.cs63
1 files changed, 36 insertions, 27 deletions
diff --git a/Analizator9000/Analizator9000/Accumulator.cs b/Analizator9000/Analizator9000/Accumulator.cs
index 36c175c..9ed04cf 100644
--- a/Analizator9000/Analizator9000/Accumulator.cs
+++ b/Analizator9000/Analizator9000/Accumulator.cs
@@ -111,7 +111,10 @@ namespace Analizator9000
for (int i = 0; i < toRun; i++)
{
Action<String> worker = this.analyzeDeal;
- worker.BeginInvoke(this.deals.Pop(), this.endAnalyze, worker);
+ lock (this.deals)
+ {
+ worker.BeginInvoke(this.deals.Pop(), this.endAnalyze, worker);
+ }
this.threadsRunning++;
}
return this.deals.Count;
@@ -178,6 +181,7 @@ namespace Analizator9000
this.abort = true;
}
+ private Object threadLock = new Object();
/// <summary>
/// Callback method for worker threads, ends the single deal analysis, updates the total result and fires next analysis if necessary.
/// </summary>
@@ -185,41 +189,46 @@ namespace Analizator9000
private void endAnalyze(IAsyncResult methodResult)
{
((Action<String>)methodResult.AsyncState).EndInvoke(methodResult);
- bool finished = false;
- if (this.abort)
- {
- this.form.setProgress(0);
- this.form.addStatusLine("Analiza przewana. Częściowe wyniki w pliku: " + this.filename);
- finished = true;
- }
- else
+ lock (this.threadLock)
{
- this.threadsRunning--;
- this.analyzed++;
- this.form.setProgress((int)(100 * this.analyzed / this.toAnalyze));
- if (threadsRunning == 0 && this.deals.Count == 0)
+ bool finished = false;
+ if (this.abort)
{
- this.form.setProgress(100);
- this.form.addStatusLine("Analiza zakończona. Wyniki w pliku: " + this.filename);
+ this.form.setProgress(0);
+ this.form.addStatusLine("Analiza przewana. Częściowe wyniki w pliku: " + this.filename);
finished = true;
- }
- if (threadsRunning < this.portionSize)
+ }
+ else
{
- // Increasing the parameter would cause exponential thread creation rate. Funny.
- this.run(1);
+
+ this.threadsRunning--;
+ this.analyzed++;
+ this.form.setProgress((int)(100 * this.analyzed / this.toAnalyze));
+ if (threadsRunning == 0 && this.deals.Count == 0)
+ {
+ this.form.setProgress(100);
+ this.form.addStatusLine("Analiza zakończona. Wyniki w pliku: " + this.filename);
+ finished = true;
+ }
+ if (threadsRunning < this.portionSize)
+ {
+ // Increasing the parameter would cause exponential thread creation rate. Funny.
+ this.run(1);
+ }
}
- }
- if (finished)
- {
- try
+ if (finished)
{
- this.outputFile.WriteLine(this.getString());
- this.outputFile.Close();
+ try
+ {
+ this.outputFile.WriteLine(this.getString());
+ this.outputFile.Close();
+ }
+ catch (Exception) { };
+ this.form.endAnalysis();
}
- catch (Exception) { };
- this.form.endAnalysis();
}
}
+
/// <summary>
/// Presents the current analysis results in textual form.