Multi-threading bug fix in Output.FileWriters.

This commit is contained in:
Milan Hanajik
2017-06-22 21:36:46 +02:00
parent 470fc6fd07
commit 7ad8c986d7
3 changed files with 32 additions and 69 deletions
@@ -27,10 +27,8 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
readonly IList<Results.WMeterRsltItemSpec> rsltItems;
Thread thread1; /// Thread where one file is saved
Thread thread2; /// Thread where another file is saved
bool completed1; /// Set to 'true' by the first thread when writing to the file completed
bool completed2; /// Set to 'true' by the second thread when writing to the file completed
Thread thread; /// Thread where one file is saved
bool completed; /// Set to 'true' by the first thread when writing to the file completed
bool abort; /// Set to 'true' by Stop() operation to abort writing to the file
@@ -142,22 +140,16 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
/// <returns>Reference to the operation</returns>
public IOperation WriteResultsOp(Results.Entities.Batch batch)
{
thread1 = new Thread(() =>
thread = new Thread(() =>
{
WriteRslts(batch, writerCfg.DestinationPath);
completed1 = true;
});
thread2 = new Thread(() =>
{
WriteRslts(batch, writerCfg.DestinationPath2);
completed2 = true;
WriteRslts(batch, writerCfg.DestinationPath2);
completed = true;
});
if (writerCfg.Culture > Culture.system && writerCfg.Culture < Culture.Count)
{
thread1.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString());
thread2.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString());
thread.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString());
}
return this;
@@ -166,27 +158,22 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
/// <summary>Start this operation</summary>
public void Start()
{
completed1 = false;
completed2 = false;
completed = false;
abort = false;
thread1.Start();
thread2.Start();
thread.Start();
}
/// <summary>Run this operation</summary>
/// <returns>Event.ResultsWritten</returns>
public Event Run()
{
if (completed1 && completed2)
return Event.ResultsWritten;
else
return Event.Busy;
}
return completed ? Event.ResultsWritten : Event.Busy;
}
/// <summary>Stop this operation</summary>
public void Stop()
{
if (!completed1 || !completed2) abort = true;
if (!completed) abort = true;
}
@@ -29,11 +29,9 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
string footer;
Thread thread1; /// Thread where one file is saved
Thread thread2; /// Thread where another file is saved
bool completed1; /// Set to 'true' by the first thread when writing to the file completed
bool completed2; /// Set to 'true' by the second thread when writing to the file completed
bool abort; /// Set to 'true' by Stop() operation to abort writing to the file
Thread thread; /// Thread where files are saved
bool completed; /// Set to 'true' when writing to files completed
bool abort; /// Set to 'true' by Stop() operation to abort writing to files
public Writer() {}
@@ -209,22 +207,16 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
/// <returns>Reference to the operation</returns>
public IOperation WriteResultsOp(Results.Entities.Batch batch)
{
thread1 = new Thread(() =>
thread = new Thread(() =>
{
WriteRslts(batch, writerCfg.DestinationPath);
completed1 = true;
});
thread2 = new Thread(() =>
{
WriteRslts(batch, writerCfg.DestinationPath2);
completed2 = true;
WriteRslts(batch, writerCfg.DestinationPath2);
completed = true;
});
if (writerCfg.Culture > Culture.system && writerCfg.Culture < Culture.Count)
{
thread1.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString());
thread2.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString());
thread.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString());
}
return this;
@@ -233,27 +225,22 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
/// <summary>Start this operation</summary>
public void Start()
{
completed1 = false;
completed2 = false;
completed = false;
abort = false;
thread1.Start();
thread2.Start();
thread.Start();
}
/// <summary>Run this operation</summary>
/// <returns>Event.ResultsWritten</returns>
public Event Run()
{
if (completed1 && completed2)
return Event.ResultsWritten;
else
return Event.Busy;
return completed ? Event.ResultsWritten : Event.Busy;
}
/// <summary>Stop this operation</summary>
public void Stop()
{
if (!completed1 || !completed2) abort = true;
if (!completed) abort = true;
}
@@ -32,9 +32,9 @@ namespace TBF.BenchControl.Output.FileWriters.Xml
IList<Results.WMeterRsltItemSpec> testItems;
Thread thread1; /// Thread where one file is saved
Thread thread; /// Thread where one file is saved
Thread thread2; /// Thread where another file is saved
bool completed1; /// Set to 'true' by the first thread when writing to the file completed
bool completed; /// Set to 'true' by the first thread when writing to the file completed
bool completed2; /// Set to 'true' by the second thread when writing to the file completed
bool abort; /// Set to 'true' by Stop() operation to abort writing to the file
@@ -188,22 +188,16 @@ namespace TBF.BenchControl.Output.FileWriters.Xml
/// <returns>Reference to the operation</returns>
public IOperation WriteResultsOp(Results.Entities.Batch batch)
{
thread1 = new Thread(() =>
thread = new Thread(() =>
{
WriteRslts(batch, writerCfg.DestinationPath);
completed1 = true;
});
thread2 = new Thread(() =>
{
WriteRslts(batch, writerCfg.DestinationPath2);
completed2 = true;
WriteRslts(batch, writerCfg.DestinationPath2);
completed = true;
});
if (writerCfg.Culture > Culture.system && writerCfg.Culture < Culture.Count)
{
thread1.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString());
thread2.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString());
thread.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString());
}
return this;
@@ -212,27 +206,22 @@ namespace TBF.BenchControl.Output.FileWriters.Xml
/// <summary>Start this operation</summary>
public void Start()
{
completed1 = false;
completed2 = false;
completed = false;
abort = false;
thread1.Start();
thread2.Start();
thread.Start();
}
/// <summary>Run this operation</summary>
/// <returns>Event.ResultsWritten</returns>
public Event Run()
{
if (completed1 && completed2)
return Event.ResultsWritten;
else
return Event.Busy;
return completed ? Event.ResultsWritten : Event.Busy;
}
/// <summary>Stop this operation</summary>
public void Stop()
{
if (!completed1 || !completed2) abort = true;
if (!completed) abort = true;
}