You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by di...@apache.org on 2008/11/16 11:50:36 UTC
svn commit: r718000 -
/incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs
Author: digy
Date: Sun Nov 16 02:50:36 2008
New Revision: 718000
URL: http://svn.apache.org/viewvc?rev=718000&view=rev
Log:
LUCENENET-135 Race condition in DocumentsWriter.UpdateDocument
Modified:
incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/SupportClass.cs?rev=718000&r1=717999&r2=718000&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs Sun Nov 16 02:50:36 2008
@@ -44,15 +44,17 @@
/// The instance of System.Threading.Thread
/// </summary>
private System.Threading.Thread threadField;
-
+
+
/// <summary>
/// Initializes a new instance of the ThreadClass class
/// </summary>
public ThreadClass()
{
threadField = new System.Threading.Thread(new System.Threading.ThreadStart(Run));
+ This = this;
}
-
+
/// <summary>
/// Initializes a new instance of the Thread class.
/// </summary>
@@ -61,8 +63,9 @@
{
threadField = new System.Threading.Thread(new System.Threading.ThreadStart(Run));
this.Name = Name;
+ This = this;
}
-
+
/// <summary>
/// Initializes a new instance of the Thread class.
/// </summary>
@@ -70,8 +73,9 @@
public ThreadClass(System.Threading.ThreadStart Start)
{
threadField = new System.Threading.Thread(Start);
+ This = this;
}
-
+
/// <summary>
/// Initializes a new instance of the Thread class.
/// </summary>
@@ -81,23 +85,29 @@
{
threadField = new System.Threading.Thread(Start);
this.Name = Name;
+ This = this;
}
-
+
/// <summary>
/// This method has no functionality unless the method is overridden
/// </summary>
public virtual void Run()
{
}
-
+
/// <summary>
/// Causes the operating system to change the state of the current thread instance to ThreadState.Running
/// </summary>
public virtual void Start()
{
threadField.Start();
+ if (This == null)
+ {
+ This = this;
+ This.Instance = threadField;
+ }
}
-
+
/// <summary>
/// Interrupts a thread that is in the WaitSleepJoin thread state
/// </summary>
@@ -105,7 +115,7 @@
{
threadField.Interrupt();
}
-
+
/// <summary>
/// Gets the current thread instance
/// </summary>
@@ -120,7 +130,7 @@
threadField = value;
}
}
-
+
/// <summary>
/// Gets or sets the name of the thread
/// </summary>
@@ -133,10 +143,10 @@
set
{
if (threadField.Name == null)
- threadField.Name = value;
+ threadField.Name = value;
}
}
-
+
/// <summary>
/// Gets or sets a value indicating the scheduling priority of a thread
/// </summary>
@@ -144,14 +154,26 @@
{
get
{
- return threadField.Priority;
+ try
+ {
+ return threadField.Priority;
+ }
+ catch
+ {
+ return System.Threading.ThreadPriority.Normal;
+ }
}
set
{
- threadField.Priority = value;
+ try
+ {
+ threadField.Priority = value;
+ }
+ catch{}
+
}
}
-
+
/// <summary>
/// Gets a value indicating the execution status of the current thread
/// </summary>
@@ -162,7 +184,7 @@
return threadField.IsAlive;
}
}
-
+
/// <summary>
/// Gets or sets a value indicating whether or not a thread is a background thread.
/// </summary>
@@ -171,13 +193,13 @@
get
{
return threadField.IsBackground;
- }
+ }
set
{
threadField.IsBackground = value;
}
}
-
+
/// <summary>
/// Blocks the calling thread until a thread terminates
/// </summary>
@@ -185,19 +207,19 @@
{
threadField.Join();
}
-
+
/// <summary>
/// Blocks the calling thread until a thread terminates or the specified time elapses
/// </summary>
/// <param name="MiliSeconds">Time of wait in milliseconds</param>
public void Join(long MiliSeconds)
{
- lock(this)
+ lock (this)
{
threadField.Join(new System.TimeSpan(MiliSeconds * 10000));
}
}
-
+
/// <summary>
/// Blocks the calling thread until a thread terminates or the specified time elapses
/// </summary>
@@ -205,12 +227,12 @@
/// <param name="NanoSeconds">Time of wait in nanoseconds</param>
public void Join(long MiliSeconds, int NanoSeconds)
{
- lock(this)
+ lock (this)
{
threadField.Join(new System.TimeSpan(MiliSeconds * 10000 + NanoSeconds * 100));
}
}
-
+
/// <summary>
/// Resumes a thread that has been suspended
/// </summary>
@@ -218,7 +240,7 @@
{
System.Threading.Monitor.PulseAll(threadField);
}
-
+
/// <summary>
/// Raises a ThreadAbortException in the thread on which it is invoked,
/// to begin the process of terminating the thread. Calling this method
@@ -228,7 +250,7 @@
{
threadField.Abort();
}
-
+
/// <summary>
/// Raises a ThreadAbortException in the thread on which it is invoked,
/// to begin the process of terminating the thread while also providing
@@ -238,12 +260,12 @@
/// <param name="stateInfo">An object that contains application-specific information, such as state, which can be used by the thread being aborted</param>
public void Abort(System.Object stateInfo)
{
- lock(this)
+ lock (this)
{
threadField.Abort(stateInfo);
}
}
-
+
/// <summary>
/// Suspends the thread, if the thread is already suspended it has no effect
/// </summary>
@@ -251,7 +273,7 @@
{
System.Threading.Monitor.Wait(threadField);
}
-
+
/// <summary>
/// Obtain a String that represents the current Object
/// </summary>
@@ -260,16 +282,22 @@
{
return "Thread[" + Name + "," + Priority.ToString() + "," + "" + "]";
}
-
+
+ [ThreadStatic]
+ static ThreadClass This = null;
+
/// <summary>
/// Gets the currently running thread
/// </summary>
/// <returns>The currently running thread</returns>
public static ThreadClass Current()
{
- ThreadClass CurrentThread = new ThreadClass();
- CurrentThread.Instance = System.Threading.Thread.CurrentThread;
- return CurrentThread;
+ if (This == null)
+ {
+ This = new ThreadClass();
+ This.Instance = System.Threading.Thread.CurrentThread;
+ }
+ return This;
}
}
@@ -972,4 +1000,4 @@
}
}
}
-}
\ No newline at end of file
+}